// external function to check all switches public void CheckAllSwitches() { // for each switch, get their script and check their status foreach (GameObject obj in switchList) { SwitchScript ss = obj.GetComponent <SwitchScript>(); // if false, can return immediately since all switches need to be true if (ss.CheckSwitch() == false) { return; } } // if all switches are pressed, check to make sure players don't have keys yet GameObject[] players = GameObject.FindGameObjectsWithTag("Player"); foreach (GameObject player in players) { PlayerController p = player.GetComponent <PlayerController>(); if (p.checkKey()) { return; } } // if all conditions passed, spawn the keys SpawnKeys(); }
// external function to check all switches public void CheckAllSwitches() { // for each switch, get their script and check their status foreach (GameObject obj in mySwitches) { SwitchScript ss = obj.GetComponent <SwitchScript>(); // if false, can return immediately since all switches need to be true if (ss.CheckSwitch() == false) { return; } } // if all switches are pressed, open gate GateScript gs = gate.GetComponent <GateScript>(); gs.GateOpen(); }