content/hifi-content/elisalj/hack_week/dj_teleport.js
2022-02-13 23:16:46 +01:00

41 lines
No EOL
1.3 KiB
JavaScript

(function(){
var teleport;
var portalDestination;
var position;
function playSound(entityID) {
print("playing teleport sound");
if (teleport.downloaded) {
Audio.playSound(teleport, { position: position, volume: 0.80, localOnly: true });
}
};
this.preload = function(entityID) {
print("loading teleport script");
teleport = SoundCache.getSound("http://s3.amazonaws.com/hifi-public/birarda/teleport.raw");
props = Entities.getEntityProperties(entityID, ["position", "userData"]);
position = props.position;
portalDestination = props.userData;
};
this.enterEntity = function(entityID) {
// get latest props in case we changed the destination
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 ....");
playSound(entityID);
};
this.unload = function() {
print("unloading teleport script");
};
})