Loading Winning UI when the timer reaches 0?
Hello,
I am kinda new to c++ and i cant seem to figure out this minor error! I am trying to load a UI that says "Level Complete" When the timer reaches 0! The place where it goes wrong is that it displays the UI at the beginning of the game not after the time hits 0! I have to scripts that modify this... My game manager and timer scripts. Here they are, i would love some help!
Scripts:
Timer:
using UnityEngine;
using System.Collections;
using UnityEngine.UI;
public class Timer : MonoBehaviour {
public float timer = 10f;
private Text timerSeconds;
public GameManager gameManager;
// Use this for initialization
void Start()
{
timerSeconds = GetComponent<Text>();
}
// Update is called once per frame
void Update()
{
timer -= Time.deltaTime;
timerSeconds.text = timer.ToString("f0");
if (timer <= 0)
{
gameManager.CompleteLevel();
}
}
}
Game Manager:
using UnityEngine;
using UnityEngine.SceneManagement;
using UnityEngine.UI;
public class GameManager : MonoBehaviour {
bool gameEnded = false;
public GameObject completeLevelUI;
public void CompleteLevel ()
{
completeLevelUI.SetActive(true);
}
public void EndGame ()
{
if (gameEnded == false)
{
gameEnded = true;
print("Game Over");
Restart();
}
}
void Restart ()
{
SceneManager.LoadScene(SceneManager.GetActiveScene().name);
}
}
Your answer
![](https://koobas.hobune.stream/wayback/20220612145515im_/https://answers.unity.com/themes/thub/images/avi.jpg)
Follow this Question
Related Questions
I need a "loop" timer that disables a action until the timer resets. 0 Answers
Countdown timer in multiple scene? 1 Answer
DateTime with countdown 0 Answers
Countdown timer... 2 Answers
Countdown timer for starting game 0 Answers