I made 2 scripts, one that is a switcher and one that checks if object is switched (Switch, SwitchCheck).
Switch script (it's on 2 objects that are switches and both objects have colliders with IsTrigger checked):
public var IsPressed : boolean = false;
function OnTriggerStay (){
if (Input.GetKeyDown(KeyCode.JoystickButton1)){
IsPressed = true;
Debug.Log("Switch activated");
}
}
SwitchCheck script (it's on door that should be opened)
public var Switch1 : Switch;
public var Switch2 : Switch;
function Update()
{
if (Switch1.IsPressed && Switch2.IsPressed)
{
Destroy (gameObject);
}
}
Now, he problem here is, that it "does" kind of work...after I press the button like 20 times. My question is, did I write something wrong?