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. Dismiss Notice

Time Counter

Discussion in 'Scripting' started by Tarik77, Apr 11, 2014.

  1. Tarik77

    Tarik77

    Joined:
    Feb 25, 2014
    Posts:
    5
    Hello,
    i've got a Problem with my time counter in my game.

    var textTime : String; function Start () {

    }

    function Update () {

    var Crono = Time.time;
    var minutos : int = Crono / 60; var segundos: int = Crono % 60; var milesimas: int = (Crono * 100)% 100; textTime = String.Format ("Time:{0:00}:{1:00}:{2:00}", minutos, segundos, milesimas); GetComponent(GUIText).text = textTime.ToString();

    }

    This is my Timer and it works perfect but the Problem is, if i won the Level or switch to another level it just goes on from my last Level so if i Finish a level it does stop but go on on the other level.
    Thanks
     
  2. bara1247

    bara1247

    Joined:
    Oct 22, 2012
    Posts:
    40
    Code (csharp):
    1.  
    2. var speed:float;
    3.  
    4. function Start()
    5. {
    6. Crono = 0;
    7. }
    8.  
    9.  
    10. function Update()
    11. {
    12. Crono +=  Time.deltaTime;
    13. }
    14.  
     
  3. Tarik77

    Tarik77

    Joined:
    Feb 25, 2014
    Posts:
    5
    Thanks works great! :)