Hi,
i know this is really basic question, but i really cant find any solution anywhere.
Thanks.
Hi,
i know this is really basic question, but i really cant find any solution anywhere.
Thanks.
You can check for a key down and put a timer in it:
private float timer = 0;
void Update() {
if (Input.anyKeyDown)
resetTimer();
else
tick();
}
void resetTimer(){
timer = 0;
}
void tick(){
timer += Time.deltaTime;
}
when your timer is bigger then a value you like, for example one minute, you can check it in Update, if( timer > 60) { restartlevel } etc.
Oh yeah, did it by myself. thanks everyone for help. here is final code:
var timer : float = 0;
function Update() {
if (Input.anyKeyDown)
resetTimer();
else
tick();
if( timer > 10)
Application.LoadLevel("futura");
}
function resetTimer(){
timer = 0;
}
function tick(){
timer += Time.deltaTime;
}
Record the time of your last input. Subtract it from the current time. If the result is higher then a threshold then reload the level
thanks. there is problem with float, it says it is unexpected token. I also hope that i added the function update correctly. so where is mistake? private float timer = 0; void Update() { if (Input.anyKeyDown) resetTimer(); else tick(); } void resetTimer(){ timer = 0; } void tick(){ timer += Time.deltaTime; } function Update () { if( timer > 10) Application.LoadLevel("futura"); }
– vojtechradaC# or UnityScript? You have a bit of both in there.
– fafaseoh, maybe that is the problem, i am trying to write it in javascript....
– vojtechrada