Hi , I have a simple script that is intended for spikes that go up and down continuously and my script works fine for that by looking at the starting position then seeing if its over or below it however I’m trying to add a small delay using the yield WaitForSeconds(); statement but it’s causing a problem. I have two variables Moveup and Movedown that change depending on the y.position of the object which then call a function but when using yield WaitForSeconds();one of the variables Moveup doesn’t switch to false so both variables are stuck on true making the object unable to move. I was just wondering what I was doing wrong as the script works fine without the yield WaitForSeconds(); statement.
thanks
heres the code
var startPos: float;
var Currentypos: float;
var Moveup = true;
var Movedown= false;
function Start()
{
startPos = transform.position.y;
}
function Update()
{
if(Moveup){
this.transform.position += transform.up *0.1;
}
if(Movedown){
this.transform.position += transform.up *-0.1;
}
Currentypos = transform.position.y;
if(Currentypos > startPos+5){
Spikedown();
}
if(Currentypos < startPos-1){
Spikeup();
}
}
function Spikedown(){
Moveup = false;
Movedown = true;
}
function Spikeup(){
Movedown= false;
[B]yield WaitForSeconds(1);[/B]
Moveup = true;
}