I have the following code :
void Start()
{
StartCoroutine(LoadObjects());
}
IEnumerator LoadObjects()
{
//load objectsA
for(int i = 0 ; i < 100 ; i++)
{
//load object A
//...
yield return new WaitForEndOfFrame();
}
//load objectsB
for(int i = 0 ; i < 100 ; i++)
{
//load object B
//...
yield return new WaitForEndOfFrame();
}
//load objectsC
//...
}
I would like to refactor and extract object loading code in separate methods :
IEnumerator LoadObjects()
{
//load objectsA
LoadObjectA();
//load objectsB
LoadObjectB();
}
IEnumerator LoadObjectA()
{
for(int i = 0 ; i < 100 ; i++)
{
//load object A
//...
yield return new WaitForEndOfFrame();
}
}
IEnumerator LoadObjectB()
{
for(int i = 0 ; i < 100 ; i++)
{
//load object B
//...
yield return new WaitForEndOfFrame();
}
}
I have tried to put “yield return” in front of “LoadObjectA();” and “LoadObjectB();” calls. While it compiles, it does not works (loading object methods are not called).
How can I have exact same behavior as before, but with code in LoadObjects splitted?