- Home /
,Pause/stop timer (waitforseconds)
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 [code]
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{
}
}
[/code]
Well, if you already have something to stop the player from jumping multiple times in mid-air, why not use that?
Answer by TripodGRANNE · Feb 01, 2012 at 02:06 AM
Try this:
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;
}
}
$$anonymous$$ANY THAN$$anonymous$$S! i was searching for this :D
Answer by DavidCoder · Feb 01, 2012 at 12:07 AM
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
Either post this as a comment, or edit your original question.
people here can help, but to know how - you have to be clear. your first question answer is if((Input.GetButton("Jump")&&(!jumping)) , your second question I cannot even understand. RE-EDIT YOUR QUESTION, only post in the comments, don't write in the answer space for your own question.
Your answer
Follow this Question
Related Questions
A node in a childnode? 1 Answer
how do I make a Time Based Score System? 1 Answer
Debug log doesn't always activate? 1 Answer
Not identifying the collider? 2 Answers