Question by
dncat · Mar 25, 2017 at 03:10 PM ·
timer countdown
timer level i need help . Im new to unity
hi everyone im new to unity and im trying to create a timer for my 3d character. My gaol is for the level have a 3 minute timer for the level im working on. any pointers? i tried looking on youtube for some tutorials.
Comment
Answer by Pengocat · Mar 25, 2017 at 04:02 PM
You could either use the Update method and the Time since the level began. public float levelTime = 180f;
// Update is called every frame, if the MonoBehaviour is enabled
void Update()
{
if (Time.timeSinceLevelLoad > levelTime)
{
LevelEnd();
}
}
void LevelEnd()
{
// Do whatever happens when the time has passed.
}
... Or a coroutine that waits for the duration and then trigger the method.
public float levelTime = 180f;
IEnumerator Start()
{
yield return new WaitForSeconds(levelTime);
LevelEnd();
}
void LevelEnd()
{
// Do whatever happens when the time has passed.
}
Your answer
![](https://koobas.hobune.stream/wayback/20220612113932im_/https://answers.unity.com/themes/thub/images/avi.jpg)