// Update is called once per frame void Update() { if (isPlayerNear) { if (hingeState == HingeState.closed || hingeState == HingeState.opened) { if (Input.GetKeyDown(KeyCode.R)) { textMesh.text = ""; hingeState = (hingeState == HingeState.closed) ? HingeState.opening : HingeState.closing; timeStartedRotation = Time.time; } } } // Update rotation if in closing or opening state if (hingeState == HingeState.closing) { if (InterpRotationY(goHinge.transform, timeStartedRotation, secondsToClose, degreesOpened, degreesClosed)) { // Done rotating hingeState = HingeState.closed; textMesh.text = "[R] Open"; } } else if (hingeState == HingeState.opening) { if (InterpRotationY(goHinge.transform, timeStartedRotation, secondsToOpen, degreesClosed, degreesOpened)) { // Done rotating hingeState = HingeState.opened; textMesh.text = "[R] Close"; } } }
public override void OnClickAction1() { switch (hingeState) { case HingeState.Closed: case HingeState.Closing: hingeState = HingeState.Opening; break; case HingeState.Open: case HingeState.Opening: hingeState = HingeState.Closing; break; } }
void FixedUpdate() { switch (hingeState) { case HingeState.Closing: rotation = Vector3.SmoothDamp(rotation, targetRotationClosed, ref rotationVelocity, rotationTime); transform.localRotation = Quaternion.Euler(rotation); if(rotation == targetRotationClosed) hingeState = HingeState.Closed; break; case HingeState.Opening: rotation = Vector3.SmoothDamp(rotation, targetRotationOpen, ref rotationVelocity, rotationTime); transform.localRotation = Quaternion.Euler(rotation); if(rotation == targetRotationOpen) hingeState = HingeState.Open; break; } }
protected virtual void Start() { hingeState = HingeState.Closed; }