When inside trigger, turn object on, when outside trigger, turn off

says it all really.

i am simply trying to make a java script to turn an object on when the player is inside a trigger cube area and then for the object to turn off on exit of the trigger area. How do i do this?

1 Answer

1

Here is an example:

var triggerOn : boolean = false;

function OnTriggerEnter () {

triggerOn = true;

}

function OnTriggerExit () {

triggerOn = false;

}

Awesome, that helps with recognising if the player is in or out of the trigger area. but what would i combine this with to to turn a seperate object on or off? say an object which is attached to my camera.

–

Your using .active wrong. Like this: GameObject.active = false; Example: var cube : GameObject; var triggerOn : boolean = true; function Update () { if (triggerOn == true) { cube.active = false; } }

–