Hi people, i doing a script that when the character jump a timer starts to verify if he is in the air… if he’r in the air for more than 2 secs it takes out 10 of hp… the problem is that when i press space the timer starts, and if a press many times in a row the timer starts verious times.
when that happens, its normal that when one of the many timers that start checks that im in the air… what i want to do is like
if(Input.GetButton("Jump"){
"code to stop the timer"
hptira();
}
function hptira(){
if(jumping)
{
if(curHealth >= 1)
{
curHealth -= 10;
}
if(curHealth == 0)
{
Application.LoadLevel(3);
}
}
else{
}
}
if(!jumping && Input.GetButtonDown("Jump")) {
"you should use a code to start the timer if they jumped"
"if they are already jumping the timer should be already counting down"
hptira();
}
}
function hptira() {
var timer = 2.0; // set timer to 2 seconds
timer -= Time.deltaTime; // subtract from timer with seconds
// you also need code to check if they landed back on the ground
if(landed) {
// code to stop timer and stop running code
}
else if(timer <= 0.0) {
curHealth -= 10;
}
}
What i want is that when i pres the space the timer stops, cuz now when i press space it starts another staying in sceane 2 timers.,The problem is that i want to stop the timers when i press the space again… cuz this way it keeps starting the timers all over again