- Home /
Calling IEnumerators
Is it possible to call IEnumerators like you would call a function/void? This for example:
void Update () {
RangedAttack(1);
}
void RangedAttack(int time) {
thisNumber = time;
}
Alternatively:
void Update () {
RangedAttack(1);
}
IEnumerator RangedAttack(int time) {
//code here
yield return new WaitForSeconds(time);
//rest of code
}
As I've tried and nothing happens. After debugging I figured it wasn't possible. If you can't, how can I stall script execution for a specified time without using WaitForSeconds() or IEnumerators?
Answer by Bovine · Jul 17, 2012 at 08:08 PM
In C# you would call a Coroutine - your RangeAttack() method - using StartCoroutine(RangedAttack(1)).
Care needs to be taken when firing off Coroutines, as naturally, you can get some pretty hairy interactions if you are firing lots of them off!
Check out Unity docs on Coroutines here:
http://docs.unity3d.com/Documentation/ScriptReference/index.Coroutines_26_Yield.html
Note that StartCoroutine() does not block.
Your answer
Follow this Question
Related Questions
IEnumerator problem 1 Answer
Get the Caller of a static function? 1 Answer
Return without Break 1 Answer
why is part of my script getting called as if it was in the Start function? 2 Answers
check bool in WaitForSeconds 2 Answers