- Home /
3D text timer
Was just wondering how i could make my 3D text count down from say 45. Thanks.
Answer by Bovine · Aug 19, 2011 at 04:15 AM
You might want to start a coroutine that changes the text every second:
IEnunerator Countdown()
{
for(int i=45; i>=0; i--)
{
my_text.Text = i.ToString();
yield return new WaitForSeconds(1);
}
}
In c# you'll need to call this with StartCoroutine() or turn it into your Start() method.
Note that I am presuming you can script Text and the geometry change - the help seems to suggest this.
You need to read about Coroutines here:
http://unity3d.com/support/documentation/ScriptReference/index.Coroutines_26_Yield.html
Basically the yield return new WaitForSeconds(1) instructs the loop to return and not be called again until 1 second has passed.
You could alternatively do this in the Update() function but it's much more of a faff and coroutines are an excellent way of doing this very thing.
I am not a java programmer but I would hope you can see the Java equivalents. You'll find coroutines a little easier to make in Java and the yield instruction is a little less verbose I think, but read the link above which will have java examples as well.
Answer by Naszia · Aug 19, 2011 at 04:46 AM
Sorry, i am super new at this and am after java, was wondering if you or someone else could go step by step. sorry but im learning :P
Your answer

Follow this Question
Related Questions
Want my UI to not move when I move my camera? 2 Answers
How to get a 3D Text to appear on collision of another object? 2 Answers
abit of a noobie question here 1 Answer
Timer and TextMesh issue.... 1 Answer
Get 3D Text size 1 Answer