- Home /
if occurs for continuesly for 3 seconds
i want it to be an if statement that sees if it lasted 3 seconds non-stop like this.
if((Car.transform.eulerAngles.z < 295) && (Car.transform.eulerAngles.z > 65)){
UpsideDown= true;
}
else{
UpsideDown = false;
}
if(UpsideDown == true){
exit();
}
function exit(){
yield WaitForSeconds(3);
if(UpsideDown == true && incar == true){
exitCar();
}
and this works but it's just that it starts when you go upside down, and 3 seconds later it checks again, if your stilkl updie down you exit, the problem is that if my car is rolling then it starts the timer then keeps rolling and eventually the player pops out, i want it to be if the car is upside down for a complete 3 seconds, were the if statement is checking the whole 3 seconds for that.
Be aware that each time the function exit is called it starts a new 3 seconds delay - even if the previous ones have not finished. If exit is called several times, 3 seconds after each call the exitCar function will be called until the variable inCar becomes false.
Answer by jahroy · Jul 19, 2011 at 04:08 AM
How about whenever the car is upright you record the time.
You could then check how long it's been since the car was upright.
If it's been more than 3 seconds, the player should exit the car.
var lastTimeUpright : float = 0.0;
function Update ()
{
if ( isUpright(carObject) ) {
lastTimeUpright = Time.time;
}
var timeSince = Time.time - lastTimeUpright;
if ( timeSince > 3.0 ) {
getOutThaCar();
}
}
function isUpright ( theCar )
{
if ( theCar.transform.eulerAngles.z > 295 ) {
return false;
}
if ( theCar.transform.eulerAngles.z < 65 ) {
return false;
}
return true;
}
thank you thank you thank you... i got it to work your idea works i did my script a little different from the one you provied but i got it to work thanks.