- Home /
Question by
paco morales · Feb 10, 2013 at 09:16 AM ·
gameobjectontriggerenterenabled
Switching between two objects using "enable"?
Hello Everyone,
I'm trying to switch between two objects with the function "enable". I did try with this script but is not working.
Also I'm using the function OnTriggerEnter, because I want to vanish one object and enabled the other object and viceversa, when my player is crossing one door.
Please any advice is more than welcome.
Please take a look to my script
var RedLed : GameObject;
var GreenLed : GameObject;
function OnTriggerEnter () {
RedLed.GameObject.enabled = ! RedLed.GameObject.enabled;
GreenLed.GameObject.enabled = ! GreenLed.GameObject.enabled;
}
Comment
Best Answer
Answer by Meater6 · Feb 10, 2013 at 09:46 AM
You probably want to use SetActive instead of enabled.
Like so
redLed.SetActive(!redLed.activeInHierarchy);
It looks like your new to scripting. You should find a tutorial here: http://answers.unity3d.com/questions/12321/how-can-i-start-learning-unity-fast-list-of-tutori.html.
Your answer
