Search Unity

  1. Welcome to the Unity Forums! Please take the time to read our Code of Conduct to familiarize yourself with the forum rules and how to post constructively.
  2. Dismiss Notice

Timer not appearing on game screen [SOLVED]

Discussion in 'Scripting' started by Troas, Jun 20, 2014.

  1. Troas

    Troas

    Joined:
    Jan 26, 2013
    Posts:
    157
    Trying to make a game timer appear on the screen while play the level

    Code so far:

    Code (CSharp):
    1. public Rect timerRect;
    2.  
    3. public float startTime;
    4. private string currentTime;
    5.  
    6. void Update (){
    7.         startTime -= Time.deltaTime;
    8.         currentTime = string.Format("{0:0.00}", startTime) ;
    9.     }
    10.  
    11. void OnGui(){
    12.         GUI.Label (timerRect, currentTime);
    13.     }
    Script is attached to an empty object. Tried rotating, transform, messing with rectangle position and w/h. The timer simply does not show up anywhere except for in the console where I can see it count down, as well as in the script where I set the start time.
     
  2. exiguous

    exiguous

    Joined:
    Nov 21, 2010
    Posts:
    1,749
    The Method name should be OnGUI() (capital u and i)
     
  3. Troas

    Troas

    Joined:
    Jan 26, 2013
    Posts:
    157
    ...Wow, thank you, I'm going to kick myself now.