Hey guys,
I have a countdown timer that works but I want it to only start when the player presses the space button. I also want the timer to reset when the player dies. When the player dies he/she re-spawns back at the start of the level but timer does not reset.
Could anyone help me? Thanks
using UnityEngine;
using System.Collections;
public class CountdownTimer : MonoBehaviour {
public GUIText _TimeText;
private float timer = 60f;
public float addTime = 10;
public GUIStyle customGuiStyle;
void Start(){
}
void OnGUI() {
int minutes = Mathf.FloorToInt(timer / 60F);
int seconds = Mathf.FloorToInt(timer - minutes * 60);
string niceTime = string.Format("{0:0}:{1:00}", minutes, seconds);
GUI.color = Color.yellow;
GUI.Label(new Rect(850,10,250,100), niceTime, customGuiStyle);
}
void Update(){
timer -= Time.deltaTime;
if (timer <= 0) {
Application.LoadLevel("Level 3 Incomplete");
}
}
void OnTriggerEnter(Collider other)
{
if(other.gameObject.tag == "PickUp")
{
Destroy(other.gameObject);
timer += addTime;
}
}
}