i have a freeze tower that freezes said enemy. would someone be so kind as to explain this in code using coroutines. any help would be appreciated.
thanks
i have a freeze tower that freezes said enemy. would someone be so kind as to explain this in code using coroutines. any help would be appreciated.
thanks
A coroutine is similar to how it sounds: a block of code that executes routinely. You make coroutines with the yield statement. Here is an example of a coroutine:
//How long to wait in seconds
var waitTime: float;
//Coroutine is in the start function because the update function can't use coroutines
function Start(){
//Be careful with while statements. If they don't have a yield statement they will freeze Unity.
//Save your work often when messing with them
while(true){
//Code to freeze your enemies
FreezeEnemy();
//Wait for waitTime in seconds
yield WaitForSeconds(waitTime);
}
}
function FreezeEnemy(){
//Code to freeze enemy
}
That’s a basic example of a coroutine. Hope I helped!