- Home /
Hitting one trigger activates all triggers?
Hi everyone,
I'm making a maze game, and I have a button object that, when the player stands on it, sends another object a message to activate. For example, if the button is connected to a door, standing on the button sends a message to the door to open.
My code works, but it appears to trigger the code on every button I have in the scene, rather than just the one which was touched. Can anyone tell me what I'm doing wrong?
#pragma strict
// DEFINE VARIABLES
static var beingUsed : boolean = false; // Is the device is currently being used?
var connectedTo : GameObject; // When the progress bar hits 100%, what object is activated/deactivated?
}
function OnTriggerEnter(obj : Collider) {
if (obj.name == "Player_Spy" || obj.name == "Player_Hacker")
beingUsed = true;
}
function OnTriggerExit() {
beingUsed = false;
}
function Update () {
if (beingUsed)
connectedTo.SendMessage("Activate", SendMessageOptions.DontRequireReceiver);
else
connectedTo.SendMessage("Deactivate", SendMessageOptions.DontRequireReceiver);
}
Comment
Best Answer
Answer by Eric5h5 · Jul 16, 2011 at 05:13 PM
Don't use static variables...static means there's only one instance of that variable even if you have many objects.