x


GUIText not working properly with a timer.

I'm trying to make a Timer Via GUIText heres my code that I attached to the GUI Text

 private var startTime         : int = 15 ;   // start time in minutes.
private var passedTime      ;
private var minutes          : int ;
private var seconds          : int ;

function Awake()
{
    // Adjusting time from minutes to seconds.
    startTime = startTime * 60; 
}


function Update()
{   
    var theTime : String ;
    var timer ;
    timer = startTime ; 
    passedTime = timer - Time.time ; 

    minutes = passedTime / 60 ; 
    seconds = passedTime % 60 ;

    theTime = String.Format ("{0:00}:{1:00}", minutes, seconds); 
}

but When I go into debug mode the text just says "GUI Text" What Am I doing wrong? also I got the code from a forum thread that I read.

more ▼

asked Jun 28 '11 at 07:09 PM

twoface262 gravatar image

twoface262
129 40 52 55

(comments are locked)
10|3000 characters needed characters left

1 answer: sort voted first

You are never assigning theTime to the GUIText's text string. Either make the GUIText a public variable and assign it with the Inspector, then set it, or use GameObject.Find in Startup to get a handle on it.

public var myText : GUIText; // set in inspector

....
  myText.text = theTime;
}

BTW: You are subtracting the current time from start time, which will always be negative, try reversing that.

more ▼

answered Jun 28 '11 at 07:42 PM

DaveA gravatar image

DaveA
26.5k 151 171 256

(comments are locked)
10|3000 characters needed characters left
Your answer
toggle preview:

Up to 2 attachments (including images) can be used with a maximum of 524.3 kB each and 1.0 MB total.

Follow this question

By Email:

Once you sign in you will be able to subscribe for any updates here

By RSS:

Answers

Answers and Comments

Topics:

x3683
x3328
x552
x347
x313

asked: Jun 28 '11 at 07:09 PM

Seen: 1259 times

Last Updated: Jun 28 '11 at 07:45 PM