Hi, I have a problem with nested coroutines…
I have a cube that contains other cubes instantiated by a class.
I want to
1- translate up the scene
2- empty the cube
3- translate down the cube
4- populate the cube
5- return to position 0 of the cube (whit its childs).
The first 4 steps are ok…
But when i use a loop inside nested coroutine that wuold move up the scene, it freezes.
Below the code;
void OnDoubleClick ()
{
DirBack.curDir = this.name;
StartCoroutine (Show (this.name, 1.0f));
}
IEnumerator Show (string dirName, float showTime)
{
yield return StartCoroutine (Hide (1.0f));
Dirs.Show (dirName); // Populate the scene cube
Files.Show (dirName); // Populate the scene cube
float showElapsedTime = 0.0f;
while (showElapsedTime < showTime) { // While loop that Freezes
showElapsedTime += Time.deltaTime;
scene.transform.position = Vector3.Lerp (scene.transform.position, new Vector3 (0, 500, 0), (showElapsedTime / showTime));
yield return new WaitForEndOfFrame ();
}
}
IEnumerator Hide (float hideTime)
{
float hideElapsedTime = 0.0f;
while (hideElapsedTime < hideTime) {
hideElapsedTime += Time.deltaTime;
scene.transform.position = Vector3.Lerp (scene.transform.position, new Vector3 (0, 500, 0), (hideElapsedTime / hideTime));
yield return new WaitForEndOfFrame ();
}
// Clear Scene and Populate Scene
foreach (Transform child in scene.transform) {
Destroy (child.gameObject);
}
scene.transform.position = Vector3.Lerp (scene.transform.position, new Vector3 (0, -500, 0), 1.0f);
}
In the gameplay i see the wired main cube blocked to y = -500 with child cubes inside.
I’ve tried for hours…what is wrong?
Nothing immediately jumps out at me, unless the behavior of WaitForEndOfFrame() has changed between versions. Try logging
– ruttershowElapsedTimeto make sure that it's increasing, at least.I've tried logging the
– areFranzshowElapsedTimeincrement... it stops at the first step (0.016....)what is that broken link?
– areFranzIt was spam/phishing. I've deleted it.
– Loius