Asii
September 29, 2012, 5:09pm
1
hello hope you can help me with this.
var canShoot : boolean = true;
function Update(){
if(canShoot){
do bullet things
canShoot = false;
}
if(!canShoot){
yield WaitForSeconds(2);
canShoot = true;
}
}
so as you can see i have problems with the yield because i cant do it in the Update function and dont know how else to do it please help!
a)
if (!canShoot){
t += 1 * Time.deltaTime;
if (t > 2){
canShoot = true;
}
}
b)
function Update(){
if (!canShoot){
YieldCooldown();
}
}
function YieldCooldown() {
yield WaitForSeconds(2);
canShoot = true;
}
c) Unity - Scripting API: MonoBehaviour.InvokeRepeating
You can not place a yield ( a coroutine) inside an Update() function. This is because yield pauses the function it is in. An update continually runs every 30 milliseconds or something, so the result is a crash.