Unity - Simple second counter C# Tutorial
Tried searching for a simple code to display seconds counter but there are nothing, here is one for sharing, the code bellow update the _textMesh with the seconds.
Second counter code:
public TextMesh _textMesh;
public float timer;
public int seconds;
private void update() {
timer += Time.deltaTime * 10;
seconds = Convert.ToInt32 (timer);
_textMesh.text = seconds.ToString();
}
If you need a count down counter just do some changes as bellow:
public TextMesh _textMesh;
public float time;
public int seconds;
private void update() {
time -= Time.deltaTime * 10;
seconds = Convert.ToInt32 (time);
_textMesh.text = seconds.ToString();
if (seconds <= 0)
// do somthing here..
}
And if you need any more help, just leave a comment.
If you like this article, please share it on facebook, tweet it and +1 it to spread it :) !
Unity - Simple second counter C# Tutorial
Reviewed by Mhr
on
12:08
Rating:
![Unity - Simple second counter C# Tutorial](https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEiyzDqpcDKBbTzkp77JDwFh9ztLlQHxBqD81-ISscUILhoTgr8pJGWlnPKYMu7fdCuH-r00t5GvEw-lcsyAeo2-WgID1JMewPOWXqPMlGdiYbhga0PRL4h9SclKQXSP2LzWn_4V4OpcW3Q/s72-c/unity3d1.jpg)
No comments
No Backlinks please, Comments are under moderation !