Hey, I was wondering if you guys could help me wrap my head around this.
I have a speed variable and I want it to increase by one incrementally, every 5 seconds. I tried using Time.time but I couldn’t set it up so that it recognized ever 5 seconds.
Hey, I was wondering if you guys could help me wrap my head around this.
I have a speed variable and I want it to increase by one incrementally, every 5 seconds. I tried using Time.time but I couldn’t set it up so that it recognized ever 5 seconds.
look up WaitForSeconds
is there a way to do that in like a function update way?
InvokeRepeating is simplest.
–Eric
Instead of WaitForSeconds you could use Unity - Scripting API: MonoBehaviour.Invoke
umm… I don’t believe it works in function update, but you could do it something like this. I don’t know if the second one will work, but the first one should work fine.
speed : float = 1.0;
speedtime : boolean = true;
function Update() {
if(speedtime){
speed ++;
speedtime = false;
}
else{
SpeedUp();
}
}
function SpeedUp() {
WaitForSeconds(5);
speedtime = true;
}
Or
speed : float = 1.0;
function Update() {
SpeedUp();
}
function SpeedUp() {
WaitForSeconds(5);
speed ++;
}
Oh cool! InvokeRepeating is AWESOME! Thanks y’all!