- Home /
Timer and TextMesh issue....
I have a TextMesh that has the time of the Timer. My starting time is 63. But I want the TextMesh to display 60 if the TIme is greater then 60 for a special reason.
I tried to do this:
if( timeLeft > 60) {
textMesh = GameObject.Find("Timer").GetComponent(TextMesh);
textMesh.text = 60;
}
But it didn't work...
How can I do this?
Answer by Mike 3 · Jun 28, 2010 at 03:29 PM
assuming textMesh is declared as var textMesh : TextMesh; somewhere and not just var textMesh; you just need to change your code to
textMesh.text = "60";
Alternatively, just clamp the value when you're displaying it (without the if timeLeft > 60 conditional):
var timeLeftClamped : int = Mathf.Clamp(timeLeft, 0, 60);
textMesh.text = timeLeftClamped.ToString();
A problem... that would change timeLeft to 60. I just want to display 60 in the text but timeLeft still stays the same. Like if the timeLeft is 63 display 60 int the text but leave the timeLeft alone.
Your answer
