Hi, I am currently trying to create a restart button for my game. It should appear when the time is up but somehow the button’s not appearing when the time’s duration is up.
using UnityEngine;
using System.Collections;
using UnityEngine.SceneManagement;
using UnityEngine.UI;
public class Restart : MonoBehaviour
{
public GameObject button;
public int timeLeft = 60;
// Use this for initialization
void Start()
{
button.SetActive (false);
}
// Update is called once per frame
void Update()
{
if (timeLeft <= 0)
{
button.SetActive (true);
StopCoroutine("LoseTime");
}
}
public void RestartGame()
{
SceneManager.LoadScene(SceneManager.GetActiveScene().name); // loads current scene
}
IEnumerator LoseTime()
{
while (true)
{
yield return new WaitForSeconds(1);
timeLeft--;
}
}
}