Consecutive Coroutines Issue

I am trying to call one corutine consecutively after another. But the second one is not working. Any ideas? I have been looking at the forums and I couldn’t find any solution.

Thank you very much!

void showComparison (Collider target)
    		{
    				key = Camera.main.ScreenToWorldPoint (key);
    				StartCoroutine (MoveFromTo (target.gameObject, target.transform.position, key, 1));    
    				GameObject player = GameObject.Find ("myPlayer");
    				StartCoroutine (MoveFromTo (player, player.transform.position, key, 1));
    
    		}

Well, moving is getting set to true and it’s defined outside the scope of MoveFromTo.

That means the 2nd call to MoveFromTo doesn’t do anything.

If you do not need the 2 routines to run concurrently what I tend to do is have one coroutine yield another. So in your example I would use

yield return MoveFromTo (player, player.transform.position, key, 1);

^ With this behavior your coroutine will yield execution until the yielded coroutine has finished executing.