Ok I have five switches in a my scene that all need to work in relation to each other. Basically when any one switch is flipped up (on) the other four will be flipped down (off). Ive got this to work going from right to left. For example switch four turns off five, three turns off four, etc. But they don’t work from left to right. I’m assuming its because once the update functions sees that switch1 is true, it has no need to search the rest of the function. Maybe i’m wrong though. Either way I cant seem to find a way for this process to work both ways.
var switch1Obj : GameObject;
private var switch1Script : SwitchAnimations;
var switch2Obj : GameObject;
private var switch2Script : SwitchAnimations;
var switch3Obj : GameObject;
private var switch3Script : SwitchAnimations;
var switch4Obj : GameObject;
private var switch4Script : SwitchAnimations;
var switch5Obj : GameObject;
private var switch5Script : SwitchAnimations;
function Awake (){
switch1Script = switch1Obj.GetComponent(SwitchAnimations);
switch2Script = switch2Obj.GetComponent(SwitchAnimations);
switch3Script = switch3Obj.GetComponent(SwitchAnimations);
switch4Script = switch4Obj.GetComponent(SwitchAnimations);
switch5Script = switch5Obj.GetComponent(SwitchAnimations);
}
function Update(){
if (switch1Script.turnedOn == true){
switch5Script.turnedOn = false;
switch4Script.turnedOn = false;
switch3Script.turnedOn = false;
switch2Script.turnedOn = false;
}
if (switch2Script.turnedOn == true){
switch3Script.turnedOn = false;
switch4Script.turnedOn = false;
switch5Script.turnedOn = false;
switch1Script.turnedOn = false;
}
if (switch3Script.turnedOn == true){
switch4Script.turnedOn = false;
switch5Script.turnedOn = false;
switch1Script.turnedOn = false;
switch2Script.turnedOn = false;
}
if (switch4Script.turnedOn == true){
switch5Script.turnedOn = false;
switch1Script.turnedOn = false;
switch2Script.turnedOn = false;
switch3Script.turnedOn = false;
}
if (switch5Script.turnedOn == true){
switch1Script.turnedOn = false;
switch2Script.turnedOn = false;
switch3Script.turnedOn = false;
switch4Script.turnedOn = false;
}
}