I have a coroutine with some nested for loops, the idea being to work through each point in a 3 dimensional array and do some stuff, but to yield the coroutine after each point so that it doesn’t halt the game while it works through the array (which is pretty big). Here’s some code;
public IEnumerator PopulateArray () {
for (int x = 0; x < maxX; x++) {
for (int y = 0; y < maxY; y++) {
for (int z = 0; z < maxZ; z++) {
// Do some stuff
// Yield until the next frame
}
}
}
}
EDIT: Added following information based on comments.
When I try “yield return null”, I get the following errors;
- “error CS0037: Cannot convert null to ‘bool’ because it is a value type”
- “error CS1662: Cannot convert ‘iterator’ to delegate type ‘code.PopulateArray()’ because some of the return types in the block are not implicitly convertible to the delegate return type”
And when I try "yield on its own I get;
- “error CS0201: Only assignment, call, increment, decrement, and new object expressions can be used as a statement”
Thank you in advanced.