Search Unity

  1. Welcome to the Unity Forums! Please take the time to read our Code of Conduct to familiarize yourself with the forum rules and how to post constructively.
  2. We have updated the language to the Editor Terms based on feedback from our employees and community. Learn more.
    Dismiss Notice
  3. Join us on November 16th, 2023, between 1 pm and 9 pm CET for Ask the Experts Online on Discord and on Unity Discussions.
    Dismiss Notice

How to put a countdown timer on my roll-a-ball unity tutorial?

Discussion in 'Scripting' started by mkhazim, Mar 17, 2015.

  1. mkhazim

    mkhazim

    Joined:
    Mar 17, 2015
    Posts:
    4
    I require a countdown timer of about 5 mins and then gameover. Script for C#
    Also I need like something to say that if i picked up all the required items = the time stops and game has been won.
     
  2. SeasiaInfotechind

    SeasiaInfotechind

    Joined:
    Nov 17, 2014
    Posts:
    32
    Go here...


    1. class Timer :MonoBehaviour{
    2. float timeLeft = 300.0f; //its 5 min = 300 sec
    3. void Update()
    4. {
    5. timeLeft -=Time.deltaTime;
    6. if( timeLeft <0)
    7. {
    8. GameOver();
    9. }
    10. }
    11. void GameOver()
    12. {
    13. // Do whatever you want to do here when timer expires..
    14. }
    15. }
     
    mkhazim likes this.
  3. jeffreyyourman

    jeffreyyourman

    Joined:
    Jul 25, 2015
    Posts:
    1
    What exactly would change this script if I wanted to add 1 second every time I picked up pickup item?