This tutorial will show us how to make one simple countdown timer.
First go to Asserts tab and click with right mouse button.
Create new C# script and open it with double clicks – left mouse button.
Drag and drop the script into your main camera.
Fill into Mono Developer with this script:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 | using UnityEngine; using System.Collections; public class timer : MonoBehaviour { public float timeRemaining = 60f; // Use this for initialization void Start () { } void Update () { if (timeRemaining > 0) { Debug.Log("Waitting..."+timeRemaining); timeRemaining -= Time.deltaTime; if ( timeRemaining == 0 ) { GameOver(); } } } void GameOver(){ } } |
Press Play Button and you will see this.
The GameOver is empty and you can put there your own game over the script.