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

race timer reset help!

Discussion in 'Scripting' started by pauloaguiar, Apr 30, 2014.

  1. pauloaguiar

    pauloaguiar

    Joined:
    May 13, 2009
    Posts:
    700
    PROBLEM SOLVED.

    I'm trying to solve a problem in counting down the clock after completing the laps or lose, reset the original values. This is when I return to the MainMenu and return to play the race again, but time keeps on last time played.
    How to reset the original values of the clock count down after loading the race?
    I know how to reset other stuff, but with this I'm confused.
    Thank you very much.

    Code (csharp):
    1. #pragma strict
    2.  
    3.  
    4. static var start : int = 0;
    5. var maxStart : int = 0;
    6. var permanentTime : int;
    7. var seconds : int;
    8. var minutes : int;
    9.  
    10.  
    11. var VoiceSoundObject : GameObject;
    12.  
    13.  
    14. private var playerHealth : masterHealthPlayer;
    15. var thePlayerHealthObj : GameObject;
    16. var showGameOverMenu : GameObject;
    17. var destroyMaterTriggers : GameObject;
    18.  
    19.  
    20. function Start ()
    21. {    
    22.     VoiceSoundObject.gameObject.SetActive(false);
    23.     showGameOverMenu.gameObject.SetActive(false);
    24.  
    25.  
    26. }
    27.  
    28.  
    29. function Update ()
    30. {    
    31.     permanentTime = start - Time.time;
    32.     minutes = permanentTime /60;
    33.     seconds = permanentTime %60;
    34.    
    35.     if (permanentTime <= 0)
    36.     {        
    37.         guiText.fontSize = 12;
    38.         guiText.text = "Time Out";    
    39.         GameOver ();        
    40.     }
    41.     else
    42.     {        
    43.         guiText.text = minutes.ToString("D2") + ":" + seconds.ToString("D2");    
    44.     }
    45.    
    46.     if (permanentTime <= 10)
    47.     {
    48.         guiText.material.color = Color.red;
    49.         VoiceSoundObject.gameObject.SetActive(true);
    50.     }
    51.     else
    52.     {    
    53.         setfalse ();
    54.         guiText.material.color = Color.blue;
    55.         guiText.fontSize = 20;
    56.     }
    57.            
    58.     if (start < maxStart)
    59.         start = maxStart;
    60. }
    61.  
    62.  
    63. function setfalse ()
    64. {
    65.     yield WaitForSeconds (0.1);
    66.     VoiceSoundObject.gameObject.SetActive(false);
    67. }
    68.  
    69.  
    70. function GameOver ()
    71. {    
    72.     Destroy(destroyMaterTriggers);
    73.     showGameOverMenu.gameObject.SetActive(true);
    74.     playerHealth = thePlayerHealthObj.GetComponent(masterHealthPlayer);
    75.     playerHealth.masterHealth -=100;
    76.     Destroy(this);
    77. }
     
    Last edited: May 2, 2014
  2. Mukabr

    Mukabr

    Joined:
    Jun 10, 2013
    Posts:
    61
    use
    Code (csharp):
    1. Time.DeltaTime
    instead of
    Code (csharp):
    1. Time.Time
     
  3. pauloaguiar

    pauloaguiar

    Joined:
    May 13, 2009
    Posts:
    700
    Does not work. Doesn't move, if use Time.DeltaTime.

    I don't know what's wrong here?
    I'm a jerk, in simple things.:(
    .
     
  4. Mukabr

    Mukabr

    Joined:
    Jun 10, 2013
    Posts:
    61
    Try changing the type of permanentTime to Float, and use Time.DeltaTime
     
  5. pauloaguiar

    pauloaguiar

    Joined:
    May 13, 2009
    Posts:
    700
    Not working, i going looking for other solution , tks anyway.