- Home /
How to make timer activated after 321 go, no at the same time?
I want my timer to activate after my countdown script has hit 1. Right now the timer activates at the same time as my 3 2 1 go script since they are two seperate Java Scripts, how do I combine them so that it goes 3 2 1 and then the timer kicks in?
FYI this is a racing game.
My CountDown script to start game 3 2 1 go!
var guiCountDown : GUIText; var countMax : int; private var countDown : int; function Start () { guiCountDown.enabled=true; GameStart();
}
function Update () {
}
function GameStart() { var car = gameObject.Find("F1Car"); var drivingScript = car.GetComponent("CarControlScript"); drivingScript.enabled=false;
for (countDown = countMax; countDown>0;countDown--){
guiCountDown.text = countDown.ToString();
yield WaitForSeconds(1);
}
guiCountDown.enabled=false;
drivingScript.enabled=true;
}
My Timer script
var timer : float = 60;
function Update () { timer -= Time.deltaTime; if(timer <- 0) { timer = 0; Application.LoadLevel("TooSlowScene"); //Does something after reaching 0 } } function OnGUI() { GUI.Box(new Rect(50, 50, 50, 20),"" + timer.ToString("0")); }
If I'm reading your code correctly.. Where you have time -= Time.deltaTime; put it in an if statement like this:
if (guiCountDown.enabled == false){
timer -= Time.deltaTime;
}
This should only activate once the guiCountDown is deactivated, which is right as the count down stops.
Answer by redeemer · Jun 01, 2015 at 11:29 PM
Hi Dakinegabe,
In my opinion you should use the new UI system if possible. I've done a really simple scene with what I think is you are trying to acomplish (the count down 3, 2, 1 is in red, Go! in green at the middle and the overall timer in black at the top). You can modify it to use GUI.Box, but I think you'll have better results and control over your UI if you change to the new UI system.
CountDown Example Scene : https://mega.co.nz/#!r8VliYzS!m3ePDHSsCzYyLpDd-pyH7Z82BeedxKg_JetYqEiCjvs
If you need any help or clarification about the scene set up or the scripts, please ask.
Hope this helps.
For some reason your CountDown Example Scene doesn't work. Could you please reattach it? Thanks
Sure, but seems weird, I just downloaded it and imported in a new project and works fine. Please, could you be more specific about how the scene doesn't work? Like, it's loading and empty scene, or you don't see anything in your camera view, etc...
Here you have a new version with the anchors corrected (maybe you were not seeing the upper timer because it was way high if you were not using the same resolution I used).
https://mega.co.nz/#!egtSAQwT!twv_Hz5dJS4FXv6WThvl21Y$$anonymous$$tQC6oOwzxzSfFcdlj$$anonymous$$c
If there's any problem with this one too please tell me and I'll post the scripts and screenshots of the scene so you can build it yourself.
Your answer
Follow this Question
Related Questions
Start timer with trigger 1 Answer
Calling methods 0 Answers
Timer doesn't work properly 2 Answers
When Score goes up by 25 change timer value 1 Answer
Countdown Through a Label? 1 Answer