Hi I have a (somehow lol) working checkpoint system ,and after each race I want to delay the time for 5 seconds then move on to the next race(level) ,its working apart from the delay part ,I am obviously putting the yield WaitForSeconds (5); code in the wrong place ? ,probably an obvious one ,but I keep getting a coroutine error
can someone please point out the obvious (again) please 
if (lap==5 && lapTime1 < 90) yield WaitForSeconds (5);
Application.LoadLevel (1):
else if (lap==5 && lapTime2 < 90)yield WaitForSeconds (5);
Application.LoadLevel (1);
else if (lap==5 && lapTime3 < 90)yield WaitForSeconds (5);
Application.LoadLevel (1);
2 Answers
2
It is much simpler than you think haha, i think you’re over looking it.
var timer : float = 0.0; // begins at this value
var timerMax : float = 3.0; // event occurs at this value
function Update()
{
timer += Time.deltaTime;
if (timer >= timerMax)
{
Debug.Log("timerMax reached !");
testObject.active = false;
}
}
Works. Thank you inglipX!
As a note: I wanted to wait x Seconds in the Update() calling a method and in a global script respectively . So in case someone else struggled with it:
private float timer = 0;
private float timerMax = 0;
void Update ()
{
text += "Allow yourself to see what you don’t allow yourself to see.";
if(!Waited(3)) return;
text += "
Press any key!";
}
private bool Waited(float seconds)
{
timerMax = seconds;
timer += Time.deltaTime;
if (timer >= timerMax)
{
return true; //max reached - waited x - seconds
}
return false;
}
lol brainlock how would this apply to my dodgy code ? if (lap==5 && lapTime1 < 90 ) timer += Time.deltaTime; if (timer >= timerMax) { Debug.Log("timerMax reached !"); Application.LoadLevel (1); } This way ?
– javanoobvar timer : float = 0.0; // begins at this value var timerMax : float = 3.0; // 3.0 seconds or however long a lap is function Update() { timer += Time.deltaTime; if (timer >= timerMax) { Debug.Log("timerMax reached !");// function at timermax testObject.active = false; Application.loadlevel(""); } }
– inglipXGot it lol I used Invoke ,very handy ,thanks though :)
– javanoob