Unexpected Co-Routine Behavior

Hello everyone, I was doing some work with coroutines and got a result I was not expecting. The critical parts of the script are below, but here is a summary:

Desired result:
//script is doing things
//coroutine suspends execution temporarily, shows debug message confirming it finished
//script continues

Actual Result:
//script is doing things
//coroutine is called
//script finishes execution
//debug message from coroutine appears (so it waited, but did not stop the script while it did)

-I realize I could put the rest of the code in the co-routine, but to keep things clean I’d rather just use the co-routine to stop the execution (which I thought it could do). Any ideas are appreciated.

	void MovePosition ()
	{
		if (nextPhase == false && inMotion == false)
		{
			transform.localPosition = Vector3.MoveTowards (transform.localPosition, endingPosition, movementSpeed * Time.deltaTime);
			if (Vector3.Distance(endingPosition, transform.localPosition) < 0.01f)
			{
				inMotion = true;
				if (inMotion == true)
				{
					StartCoroutine (WaitForRetract(rectractTimer));
					nextPhase = true;
					Debug.Log ("next pahse is " + nextPhase + " called from 1st block");
					inMotion = false;
					Debug.Log ("in motion is " + inMotion + " called from 1st block");
				}
			}
		}

	IEnumerator WaitForRetract (float time)
	{
		yield return new WaitForSeconds (time);
		Debug.Log ("I finished waiting");
	}

Only coroutines get to say “wait here for a while.” Only they have the ability to be packed away in the middle of running, then restarted at that point. Everything else has to just run, run ,run. So, what you are seeing is the proper behavior.

In your case, you would use YIELD StartCoroutine (WaitForRetract(rectractTimer));. But that would only be allowed if MovePosition were itself a coroutine. But then you could just use WaitForSeconds directly.

Depending on what you are trying to do, some timing issues are best handled with a timer variable (and no coroutines): startPhaseOneTime = Time.time+2.0f; and if(Time.time>startPhaseOneTime).