I have a class like so:
public class SomeObject : MonoBehaviour
{
protected List<EdibleStuff> SomeItemsToConsume;
private void StartConsuming()
{
this.SomeItemsToConsume
.ForEach(item =>
{
StartCoroutine(Consume(item));
});
}
private IEnumerator Consume(EdibleStuff edibleStuff)
{
yield return new WaitForSecondsRealtime(2);
// Check whether edibleStuff is still fresh after 2 seconds
// Figure out how to consume it -- e.g. by cooking, eating raw, whatever
}
}
Before SomeObject consumes the next item in the SomeItemsToConsume list, I would like it to wait another short period of time, say, another 2 seconds.
I have tried these approches:
- I added another
yield return new WaitForSecondsRealtime(2);statement at the end of theConsume(EdibleStuff edibleStuff)method, but that did not work. - I added another co-routine, which simply contains the statement
yield return new WaitForSecondsRealtime(2);in its definition, at the end of theForEachloop, but that did not work either.
How can I achieve the effect I want?