virtual protected void OnDeactivation() { counter = 0; PlayPlugOutSound(); if (isLeftPlugged) { isLeftPlugged = false; isPlugOutEnabled = false; leftArm.OnPlugOut(); return; } if (isRightPlugged) { isRightPlugged = false; isPlugOutEnabled = false; rightArm.OnPlugOut(); return; } }
private void ActivateSwitch() { if (Input.GetKeyDown(KeyCode.Q)) { // If this switch is plugged in by eiher right or left if (isLeftPlugged || isRightPlugged) { // Activating switch if (!isActivated) { // Activate only when the plugged hand is being controlled if ((isLeftPlugged && leftHand.GetControl()) || (isRightPlugged && rightHand.GetControl())) { isActivated = true; Invoke("Deactivate", 0.5f); } } } else { // Plugging into switch if (isLeftHandAround && !isLeftPlugged && leftHand.GetControl()) { isLeftPlugged = true; leftHand.OnPlugIn(); return; } if (isRightHandAround && !isRightPlugged && rightHand.GetControl()) { isRightPlugged = true; rightHand.OnPlugIn(); return; } } } if (Input.GetKey(KeyCode.Q) && isPlugOutEnabled) { if (isLeftPlugged && leftHand.GetControl()) { if (counter++ > waitToPlugOut) { isLeftPlugged = false; leftHand.OnPlugOut(); isPlugOutEnabled = false; } } if (isRightPlugged && rightHand.GetControl()) { if (counter++ > waitToPlugOut) { isRightPlugged = false; rightHand.OnPlugOut(); isPlugOutEnabled = false; } } } if (Input.GetKeyUp(KeyCode.Q)) { counter = 0; if ((isLeftPlugged && leftHand.GetControl()) || (isRightPlugged && rightHand.GetControl())) { isPlugOutEnabled = true; } } }