// Start is called before the first frame update void Start() { _player = GameObject.FindGameObjectWithTag("Player"); //Get the code lock and its script _parentCodeLock = transform.parent.gameObject; _codeScript = _parentCodeLock.GetComponent <Read_Code>(); _buttonPressSFX = GetComponentInChildren <AudioSource>(); }
//Method to check the power from whatever input is attached to this component //such as a switch or the control panel bool CheckInputs() { int poweredCount = 0; for (int i = 0; i < inputObjects.Length; ++i) { GameObject obj = inputObjects[i]; switch (obj.tag) { case "Control Panel": FuseBox_Puzzle panelScript = obj.GetComponent <FuseBox_Puzzle>(); if (panelScript.GetPowerState()) { ChangeLights(i, true); poweredCount++; } break; case "Keycard Reader": Read_Keycard keycardScript = obj.GetComponent <Read_Keycard>(); //Flip the state of the "IsLocked" method for consistency bool _keyCardReaderUnlocked = !keycardScript.IsLocked(); if (_keyCardReaderUnlocked) { ChangeLights(i, true); poweredCount++; } break; case "Codelock": Read_Code codeLockScript = obj.GetComponent <Read_Code>(); if (codeLockScript.IsUnlocked()) { ChangeLights(i, true); poweredCount++; } break; case "Power Switch": Power_Switch switchScript = obj.GetComponent <Power_Switch>(); if (switchScript.getActiveState()) { //Debug.Log("Switch flipped"); ChangeLights(i, true); poweredCount++; } else { ChangeLights(i, false); poweredCount--; } break; case "Generator Switch": Generator_Switch genSwitchScript = obj.GetComponent <Generator_Switch>(); if (genSwitchScript.IsFlipped()) { ChangeLights(i, true); poweredCount++; } break; default: throw new UnityException("Invalid input object attached to " + gameObject.name); } } return(poweredCount == inputObjects.Length); }