- Home /
 
How to add a counter on screen!
I've created this script in javascript. var endTime : float; var textMesh : TextMesh;
 function Start()
 {
 endTime = Time.time + 60;
 textMesh = GameObject.Find ("Timer").GetComponent(TextMesh);
 textMesh.text = "60";
 }
  
 function Update()
 {
 var timeLeft : int = endTime - Time.time;
 if (timeLeft < 0) timeLeft = 0;
 textMesh.text = timeLeft.ToString();
 }
 
               Would i need to add a guitext and change some code?
Yep, you can either create one with OnGUI function, or just create one in the editor.
Answer by Brum · Oct 13, 2013 at 04:40 PM
If you want just simple plain text you could just use the OnGUI method:
http://docs.unity3d.com/Documentation/Components/GUIScriptingGuide.html
The code i've created above is used as a countdown for a game i am making but i've tryed assigning it to a GUIText but that won't work, neither will calling the GUIFunction
Answer by Cherno · Oct 13, 2013 at 08:47 PM
 var Counter : float;
 
 function Update()
 {
     Counter += Time.deltaTime;
 }
 
 function OnGUI()
 {
     GUI.Label (Rect (Screen.width / 2 - 50, Screen.height / 2 - 50, 100, 100), Counter + "");
 
 }
 
 
 
              Your answer
 
             Follow this Question
Related Questions
countdown/countup timer 1 Answer
C# countdown timer 9 Answers
How to stop a countdown from counting down 1 Answer
Countdown timer into text c# 1 Answer
How to restart a level with countdown? 4 Answers