- Home /
How to play the animation when time countdown is out
like in the title,I'm making a simple game that have 60 sec. to grab item as much as you can and when the timer is out,I want to play animation that pop the restart buttom up anyone can help me about this? thanks :) this is my Timer code.
using UnityEngine; using System.Collections; using UnityEngine.UI;
public class Timer : MonoBehaviour { public int timeLeft = 1; public Text countdownText;
Animator anim;
void Awake()
{
anim = GetComponent<Animator>();
}
void Start()
{
StartCoroutine("LoseTime");
}
void Update()
{
countdownText.text = ("TimeLeft : " + timeLeft + " Sec.");
if (timeLeft <= 0)
{
anim.SetTrigger ("GameOver");
StopCoroutine("LoseTime");
countdownText.text = ("Time's UP!!!!");
}
}
IEnumerator LoseTime()
{
while (true)
{
yield return new WaitForSeconds(1);
timeLeft--;
}
}
}
Answer by LCStark · Oct 10, 2018 at 05:50 PM
Use Time.deltaTime
(docs: https://docs.unity3d.com/ScriptReference/Time-deltaTime.html).
Your answer
Follow this Question
Related Questions
Can the animation editor create local rotational data? 3 Answers
Animation timer problem 0 Answers
Adding animation clips via script 2 Answers
Cooldown indication, transparent rotating texture 1 Answer
Reverse animation problem 1 Answer