void EnableComponents() { //Turn the light "on" by setting its material to the deactive (red) light MeshRenderer lightRenderer = _attachedLight.GetComponent <MeshRenderer>(); lightRenderer.material = _startingMat; //Activate the switch so it can be toggled Power_Switch switchScript = GetComponent <Power_Switch>(); switchScript.enabled = true; //Toggle the activated bool so this activation only occurs once _activated = true; }
//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); }