Search Unity

  1. Megacity Metro Demo now available. Download now.
    Dismiss Notice
  2. Unity support for visionOS is now available. Learn more in our blog post.
    Dismiss Notice

How to make a timer?

Discussion in 'Getting Started' started by LumoKvin, Nov 14, 2019.

  1. LumoKvin

    LumoKvin

    Joined:
    Sep 28, 2019
    Posts:
    195
    Is this currently the best way to make a timer? Will it be consistent across devices and different frame rates?

    Code (CSharp):
    1. float timeLeft = 10f;
    2. function Update()
    3. {
    4.      timeLeft -= Time.deltaTime;
    5.      if ( timeLeft < 0 )
    6.      {
    7.          GameOver();
    8.      }
    9. }
     
  2. Joe-Censored

    Joe-Censored

    Joined:
    Mar 26, 2013
    Posts:
    11,847
    Ryiah and JoeStrout like this.