问题
I am making a card game in which I am trying to make a (0.5f) delay before each card is instantiated. I have my code which instantiates and object
public IEnumerator Name(int x,int y, int z)
{
}
In the IEnum i have a yeild return new WaitForSeconds(0.5f)
before all the code with the instantiation.
I call my IEnumerator in 2 different classes 2 times in each by using
StartCoroutine(Name(...par...));
And on my play game button i have 4 events which use the enum to spawn the cards but there is no delay .
Is there a way to make the cards appear 1 by one .
Thanks for any support.
回答1:
Whatever it is that is currently calling StartCoroutine needs to be the coroutine.
Right now you have code that looks/behaves like this:
StartCoroutine(Name(...par...));
StartCoroutine(Name(...par...));
StartCoroutine(Name(...par...));
StartCoroutine(Name(...par...));
And all of them are spawning a card and not waiting for each other. You don't want this, so you're going to need to make a fundamental change in how your calls are made so that you can get this behavior:
StartCoroutine(SomeMethod(...));
IEnumerator SomeMethod(...) {
yield return Name(...par...)
yield return Name(...par...)
yield return Name(...par...)
yield return Name(...par...)
}
来源:https://stackoverflow.com/questions/52194492/how-to-use-ienumerator-correctly-when-button-calls-multiple-functions