unity 3d student

Beginner B06 – Simple Timer


How to make a simple scripted timer in Unity using Time.deltaTime and a float variable.

Code Used

//A simple countdown timer
  1. var myTimer : float = 5.0;
  2.  
  3. function Update () {
  4.  if(myTimer > 0){
  5.   myTimer -= Time.deltaTime;
  6.  }
  7.  if(myTimer <= 0){
  8.   Debug.Log("GAME OVER");
  9.  }
  10. }

Further Reading

Share via Social Media

  • Digg
  • StumbleUpon
  • del.icio.us
  • Facebook
  • Yahoo! Buzz
  • Twitter
  • Google Bookmarks
  • Add to favorites

46 Comments