Search Unity

Create a GUI Text timer?

Discussion in 'Scripting' started by Treasureman, May 27, 2015.

  1. Treasureman

    Treasureman

    Joined:
    Jul 5, 2014
    Posts:
    563
    I want to make a "Call of Duty" type timer in my game using GUI Text. Starting at 10:00 to 9:59 to 9:58 to 9:57, so on, so forth. How would I do this? All I need is a script that makes it only do this to like 9:55 and I can do the rest from there. Thanks if you can help!
     
  2. Kurt-Dekker

    Kurt-Dekker

    Joined:
    Mar 16, 2013
    Posts:
    38,752
    Generally for these types of things you want to keep the following points in mind:

    - use a single variable (usually a float) to denote the remaining time, usually in seconds. This is the only value that you would count down.

    - use division and modulo math to calculate (every time you go to update the display) how many hours, minutes, seconds, and 10ths or 100ths there are left.

    - use System.String.Format() to construct a coherent display of the above items, such as 0:00.0 for instance.