- Home /
Question by
riskaanisah · Nov 12, 2018 at 12:56 PM ·
timertimescaletimer countdown
how to make the timer stop and can automatically proceed to the next scene
Image timerBar; public float maxTime = 5f; float timeLeft;
// Use this for initialization
void Start () {
timerBar = GetComponent<Image>();
timeLeft = maxTime;
}
// Update is called once per frame
void Update () {
if (timeLeft > 0)
{
timeLeft -= Time.deltaTime;
timerBar.fillAmount = timeLeft / maxTime;
}
else
{
SceneManager.LoadScene("GameOverDD");
Time.timeScale = 0;
}
}
public float delay = 1;
[SerializeField]
private GameObject PanelBenar;
[SerializeField]
private GameObject PanelSalah;
void Start()
{
PanelBenar.SetActive(false);
PanelSalah.SetActive(false);
}
void Update()
{
if (Slot10.cek)
{
GameObject objek1 = GameObject.FindGameObjectWithTag("Benar1");
GameObject objek2 = GameObject.FindGameObjectWithTag("Benar2");
if (objek1.transform.parent.tag == "Jawab1")
{
PanelBenar.SetActive(true);
Time.timeScale = 0;
StartCoroutine(LoadLevelAfterDelay21(delay));
}
else
{
Time.timeScale = 0;
PanelSalah.SetActive(true);
StartCoroutine(LoadLevelAfterDelay20(delay));
}
}
}
IEnumerator LoadLevelAfterDelay21(float delay)
{
yield return new WaitForSeconds(delay);
SceneManager.LoadScene("DragDrop21");
}
IEnumerator LoadLevelAfterDelay20(float delay)
{
yield return new WaitForSeconds(delay);
SceneManager.LoadScene("DragDrop20");
}
Comment
Your answer
![](https://koobas.hobune.stream/wayback/20220612182007im_/https://answers.unity.com/themes/thub/images/avi.jpg)
Follow this Question
Related Questions
How do I make the timeScale not affect the timer? 1 Answer
two different collider in one script 1 Answer
How to to do a progress bar wich scale down in 6 seconds ? (timeScale used) 0 Answers
Timer not working in prefabs 0 Answers
How do I stop 'timeSinceLevelLoad' without pausing entire game? 2 Answers