Question by
contatogcriation · Mar 15, 2019 at 03:02 PM ·
c#2d
Reset for countdown timer - Game Quiz
I need reset my countdown timer in every anwers in my quiz game in 2D. My code is:
using System.Collections;
using UnityEngine;
using UnityEngine.UI;
public class TimerScript : MonoBehaviour {
Image LinearTimer;
public float maxTime = 5f;
float timeLeft;
public GameObject timesUpText;
// Use this for initialization
void Start()
{
timesUpText.SetActive(false);
LinearTimer = GetComponent<Image>();
timeLeft = maxTime;
}
// Update is called once per frame
void Update () {
if (timeLeft > 0) {
timeLeft -= Time.deltaTime;
LinearTimer.fillAmount = timeLeft / maxTime;
} else {
Application.LoadLevel("gameover");
Time.timeScale = 0;
}
}
}
Comment