IEnumerator Rotate() { if (!rotating) { rotating = true; // set the flag targetRot.x = currentRot.x + 90.0f; // calculate the new angle while (currentRot.x < targetRot.x) { currentRot.x = Mathf.MoveTowardsAngle(currentRot.x, targetRot.x, DegreesPerSecond * Time.deltaTime); transform.eulerAngles = currentRot; yield return(null); } rotating = false; if (currentColour != CubeColour.White) { currentColour++; } else { currentColour = CubeColour.Red; } } }
// Use this for initialization void Awake() { currentColour = CubeColour.Red; }