0

Hi guys good evening .

I have a problem for timer . when i press a play button the countdown is display number 3 only . I used 3d text not GUI text , because my GUI text is not working so that i used 3D text.

This is my code for COuntdown.js

    #pragma strict

var guiCountDown : TextMesh;
var countMax : int;
private var countDown : int;

function Start(){
guiCountDown.active = true;
GameStart();
}



 function GameStart(){
var car = gameObject.Find("Car");
var drivingScript = car.GetComponent("Car");
drivingScript.active = false;

var timer = GetComponent("Timer");
timer.active = false;

for(countDown = countMax; countDown >= 0; countDown--){
Debug.Log("Count: " + countDown);
if(countDown == 0){
guiCountDown.text = "GO!";
}
else
guiCountDown.text = countDown.ToString(); 
yield WaitForSeconds(1);
}

guiCountDown.active = false;
drivingScript.active = true;
timer.active = true;
}

and this is my code in TImer.js

#pragma strict

var pastTime : float;

var guiTime : TextMesh;

function Update (){
pastTime += Time.deltaTime;
guiTime.text = pastTime.ToString ();

}

Help me guys.

CodeSmile
  • 64,284
  • 20
  • 132
  • 217

1 Answers1

0

You disable the timer in the coroutine and enable it in the end. The Update loop for the Timer.js will not be running.

Esa
  • 1,636
  • 3
  • 19
  • 23