- Home /
The question is answered, right answer was accepted
yield return new WaitForSeconds (); in c#
Hi, how can I make it work? I mean the line is working, but the void doesn't allow it to run:
void Smite(){
yield return new WaitForSeconds (1.3f);
Die();
I get error: Assets/Scripts/AI/EnemyScript.cs(55,14): error CS1624: The body of EnemyScript.Smite()' cannot be an iterator block because
void' is not an iterator interface type
help please, and thanks in advance.
Answer by LukaKotar · Jul 20, 2013 at 05:10 PM
IEnumerator Smite(){
yield return new WaitForSeconds (1.3f);
Die();
No problem. By the way, Send$$anonymous$$essage() should call the function, but you cannot do for example Smite();
, you need to do StartCoroutine("Smite");
, or StartCoroutine(Smite());
to initiate it.
Answer by $$anonymous$$ · Jul 20, 2013 at 05:10 PM
You cannot use yield in void functions. http://docs.unity3d.com/Documentation/ScriptReference/index.Coroutines_26_Yield.html
IEnumerator Example()
{
yield return new WaitForSeconds(5.0F);
}
ok can you explain better for my code? by the way the void Smite is called from another script (Send$$anonymous$$essage)
Follow this Question
Related Questions
function with yield WaitForSeconds doesn't run 3 Answers
Multiple Cars not working 1 Answer
Distribute terrain in zones 3 Answers
Custom Yield Instruction for FixedUpdate frames 3 Answers
C# syntax seems fine, why wont yeild work? (Unsolved) 1 Answer