In my game I have a timer that will countdown from 10, but if the player hits these orbs then I want to have an additional 5 seconds be added to the timer.
Here is my timer code.
using UnityEngine;
using System.Collections;
public class Timer : MonoBehaviour {
public float time = 11;
IEnumerator Do() {
yield return new WaitForSeconds(3);
Application.LoadLevel(Application.loadedLevel);
}
// Use this for initialization
void Start () {
}
void Update () {
time -= Time.deltaTime;
}
void OnGUI(){
if (time > 1) {
GUI.Label (new Rect (100, 100, 200, 100), "" + (int)time);
}
else {
GUI.Label (new Rect (100, 100, 200, 100), "Game Over");
StartCoroutine(Do());
}
}
}
Here is my collsion.
using UnityEngine;
using System.Collections;
public class Des : MonoBehaviour {
void OnTriggerEnter(Collider other) {
Destroy(other.gameObject);
}
}
Also I was looking for a way to make the timer not be able to go past 20 seconds. For that i was thinking about something like
if(time >= 20){
time = 20;
}