public void Rotate(Vector3 axis) { if (State != CubesState.Idle) return; State = CubesState.Rotating; targetRotation = Quaternion.AngleAxis(90, axis) * transform.localRotation; }
public void Rotate(Vector3 axis) { if (State != CubesState.Idle) { return; } State = CubesState.Rotating; targetRotation = Quaternion.AngleAxis(90, axis) * transform.localRotation; }
private void Update() { if (State == CubesState.Rotating) { var fraction = AutoRotationSpeed * Time.deltaTime; transform.localRotation = Quaternion.Slerp(transform.localRotation, targetRotation, fraction); if (Quaternion.Angle(transform.localRotation, targetRotation) < .1) { transform.localRotation = targetRotation; State = CubesState.Idle; } } else { var fraction = RotationSpeed * Time.deltaTime; transform.localRotation = Quaternion.Slerp(transform.localRotation, targetRotation, fraction); } }