Question by
DubstepCheesecake · Jun 07, 2017 at 06:01 AM ·
unity 5buttontimer
Button still not appearing
I have created a button that should appear when the time runs out but it's not appearing.
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()
{
StartCoroutine("LoseTime");
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--;
}
}
}
Comment