overte-thingvellir/examples/toys/flashlight/createFlashlight.js
Thijs Wenker 6bb873d327 createFlashlight.js - Close script after running
Close the createFlashlight.js script after running once to prevent a flashlight from being created each time you start Interface
2015-09-24 00:43:50 +02:00

52 lines
1.4 KiB
JavaScript

//
// createFlashlight.js
// examples/entityScripts
//
// Created by Sam Gateau on 9/9/15.
// Copyright 2015 High Fidelity, Inc.
//
// This is a toy script that create a flashlight entity that lit when grabbed
// This can be run from an interface and the flashlight will get deleted from the domain when quitting
//
// Distributed under the Apache License, Version 2.0.
// See the accompanying file LICENSE or http://www.apache.org/licenses/LICENSE-2.0.html
//
Script.include("https://hifi-public.s3.amazonaws.com/scripts/utilities.js");
var scriptURL = Script.resolvePath('flashlight.js?123123');
var modelURL = "https://hifi-public.s3.amazonaws.com/models/props/flashlight.fbx";
var center = Vec3.sum(Vec3.sum(MyAvatar.position, {
x: 0,
y: 0.5,
z: 0
}), Vec3.multiply(0.5, Quat.getFront(Camera.getOrientation())));
var flashlight = Entities.addEntity({
type: "Model",
modelURL: modelURL,
position: center,
dimensions: {
x: 0.08,
y: 0.30,
z: 0.08
},
collisionsWillMove: true,
shapeType: 'box',
script: scriptURL
});
function cleanup() {
//commenting out the line below makes this persistent. to delete at cleanup, uncomment
//Entities.deleteEntity(flashlight);
}
Script.scriptEnding.connect(cleanup);
// Close script after running once to prevent a flashlight from being created each time you start Interface
Script.stop();