- Home /
how to a count on the screen on UPDATE
Hi guys, i have a GameObject called Player, and when it dies i want to preform a count on the screen before respawning him,
I now that i can use the GUI.Label but i would like it to be during the update method and not on the OnGUI method, and i would like to choose the font size as well
thanks in advance
Gal
Comment
Best Answer
Answer by hbalint1 · Apr 13, 2015 at 02:41 PM
You can handle GUI elements only in OnGUI() method. You should make something like this:
private bool isDead;
private CountDownTimer respawnTimer;
void Start()
{
isDead = false;
}
void Update()
{
if(respawnTimer.GetValue() <= 0)
{
respawnTimer.Stop();
respawnTimer.Reset(); // these two lines for prevent the looping and the multiple Spawn
Spawn();
}
}
void Spawn()
{
... // spawning player
isDead = false;
}
void OnGUI()
{
if(isDead)
GUI.Label(new Rect(Screen.width / 2, 10, 200, 20), "Respawn in: " + HideTimer.GetTimerAsString());
}
void Die()
{
isDead = true;
respawnTimer.Set(10); // 10 sec to respawn
respawnTimer.Start();
}
Of course you can replace my CountDownTimer class with your own timer class. This is just an idea on how to do it. I use this in my game too.
great thanks i thought there will be another way but thats ok too