title: Optimizing Unity Code - InvokeRepeating / StartCoroutine
body: <p>I have a PowerUp with a countdowntimer. For the timer i use InvokeRepeating. But I could also use StartCoroutine.</p>
  
  <p>So which one to choose? I don't really get the difference...</p>
  
  <p>Here my code:</p>
  
  <pre><code>float powerUpDuration = 5;               // the duration of the buff
      float slowMotionTimeScale = 0.5f;     // slow down the player by 0.5
      float defaultTimeScale = 1;              // the normal game speed
      private void OnTriggerEnter(Collider collision)     // player colliding with powerUp
      {
              if (collision.gameObject.tag == "Player")
              {
                      Time.timeScale = slowMotionTimeScale;     // time gets slowed
                      Time.fixedDeltaTime = Time.fixedDeltaTime * Time.timeScale;     // smooth slow down
                      InvokeRepeating("SpeedManager", 0, 1); // start countdown
              }
      }
      void SpeedManager()
      {
              if (powerUpDuration &gt; 0)         // count to 0
              {
                      powerUpDuration--;
              }
              else              // stop countdown, set timespeed to default
              {
                      CancelInvoke("SpeedManager");
                      Time.timeScale = defaultTimeScale;
                      powerUpDuration = 5;                 // reset timer
              }
      }
  </code></pre>