Question by
Yots · May 26, 2020 at 03:49 PM ·
scripting problemscript.scene-loadinggame development
how to fix countdown bug after reset level?
hello guy i need help how can fix this bug in the first start level it run normal but after reset level timer has get stuck and don't countdown
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.UI;
public class Timeingame : MonoBehaviour
{
public float countdown;
public Text countdownText;
public Text endText;
public bool timeup = false;
void Start()
{
endText.gameObject.SetActive(false);
StartCoroutine(timedown());
}
IEnumerator timedown()
{
while (countdown > 0)
{
countdownText.text = countdown.ToString("0");
yield return new WaitForSeconds(1f);
countdown--;
}
timeup = true;
countdownText.text = "0";
endText.gameObject.SetActive(true);
endText.text = "Time up";
yield return new WaitForSeconds(3f);
endText.gameObject.SetActive(false);
}
}
Comment