I want that each time I click with my mouse, DoNextAction() is called and execute instructions until the yield return is called. That is normally how ‘foreach iterators’ work.
(The first click should print “First”, then if I click again “Second”, etc…)
The problem is that each time I click, DoNextAction does nothing.
And I don’t want to use StartCoroutine(), because if I do:
void Update()
{
if (Input.GetMouseButtonDown(0))
{
StartCoroutine(DoNextAction());
}
}
StartCoroutine will do all the yields (each time click, it would print “First”, “Second”, “Third” and “Finish” all at once…)
First off all, you can´t… following unity reference:
When using JavaScript it is not necessary to use StartCoroutine, the compiler will do this for you. When writing C# code you must call StartCoroutine.
So to use yield you need a StartCoroutine, your actual problem is the idea of yield.
The yield will continue in the next update, although the function is called or no.
What I suggest to do is not using yield, try to do a case function with a tick counter? Maybe every time you click it´s add a counter and for each click it does that function. That make more sense for me.
If you want to use yield anyway. You should know that wield wait for a function to complete, so for example, wait for seconds will expend X seconds to end, and the function will go after that ends.
Sorry about the english, or seemed rude, not my native language…