title: Why doesn't my IEnumerator function loop?
body: <p>I have an object that I want to loop when I press the U key using Quaternion: </p>
  
  <pre><code> public KeyCode UTurn;
  
      void UNotation()
      {
          if (Input.GetKeyDown(UTurn)) {
  
              Quaternion rotation2 = Quaternion.Euler(new Vector3(0, 90, 0));
              StartCoroutine (rotateObject(objectToRotate, rotation2, 1f));
              // Debug.Log("Turn: U");
          }
      }
  </code></pre>
  
  <p>Then, I have my <code>IEnumerator</code> function that allows my object to rotate in 2 seconds, like this: </p>
  
  <pre><code> bool rotating = false;
      public GameObject objectToRotate;
  
      IEnumerator rotateObject(GameObject gameObjectToMove, Quaternion newRot, float duration)
      {
          Debug.Log("Accessed IEnumerator function...");
          if (rotating)
          {
              yield break;
          }
  
          rotating = true;
  
  
          Quaternion currentRot = gameObjectToMove.transform.rotation;
  
          float counter = 0;
          while (counter &lt; duration)
          {
              counter += Time.deltaTime;
  
              Debug.Log("Rotated!");
  
              gameObjectToMove.transform.rotation = Quaternion.Lerp(currentRot, newRot, counter / duration);
  
              yield return null;
  
          }
  
          rotating = false;
      }
  </code></pre>
  
  <p>I then call the <code>UNotation()</code> function in the <code>Update()</code> function: </p>
  
  <pre><code> void Update () {
          UNotation();
      }
  </code></pre>
  
  <p>I want to be able to <strong>continue rotating the cube again and again</strong> pressing the U key once each rotation has finished, but for some reason I can only get the object to rotate <strong>once</strong> and then it doesn't rotate anymore, however the two <code>Debug.Log</code> calls in the <code>IEnumerator</code> function gets checked to console just fine, so for some reason this line stops working: </p>
  
  <pre><code>gameObjectToMove.transform.rotation = Quaternion.Lerp(currentRot, newRot, counter / duration);
  </code></pre>
  
  <p>I've tried making a loop inside the function but it ended up crashing my game. Appreciate any help!</p>