(function(){ var teleport; var portalDestination; var animationURL; var position; function playSound(entityID) { print("playing teleport sound"); if (teleport.downloaded) { if(!position) { getProps(entityID); } Audio.playSound(teleport, { position: position, volume: 0.40, localOnly: true }); } }; function getProps(entityID) { var properties = Entities.getEntityProperties(entityID); if (properties) { animationURL = properties.modelURL; position = properties.position; portalDestination = properties.userData; } }; this.preload = function(entityID) { print("loading teleport script"); teleport = SoundCache.getSound("http://s3.amazonaws.com/hifi-public/birarda/teleport.raw"); getProps(entityID); }; this.enterEntity = function(entityID) { // get latest props in case we changed the destination getProps(entityID); print("enterEntity() .... The portal destination is " + portalDestination); if (portalDestination.length > 0) { print("Teleporting to hifi://" + portalDestination); Window.location = "hifi://" + portalDestination; } }; this.leaveEntity = function(entityID) { print("leaveEntity() called ...."); if (!animationURL) { getProps(entityID); } Entities.editEntity(entityID, { animation: { url: animationURL, currentFrame: 1, running: false } }); playSound(entityID); }; this.hoverEnterEntity = function(entityID) { print("hoverEnterEntity() called ...."); if (!animationURL) { getProps(entityID); } Entities.editEntity(entityID, { animation: { url: animationURL, fps: 24, firstFrame: 1, lastFrame: 25, currentFrame: 1, running: true, hold: true } }); }; this.unload = function() { print("unloading teleport script"); }; })