Yield WaitForSeconds not working > once in coroutine

Hey guys!

I am having an issue with a bit of code that was working fine before, but decided to not work 2 days before the project it’s for is due.

What I wanted was the camera to Lerp from one point to another taking a certain amount of time. It was then to wait there for a certain amount of time, then go back to it’s original position.

here is what the coroutine looks like:

IEnumerator cameraMove (){
		
		duration = durationToEnd;
		fromPos = startAt;
		toPos = endAt;
			
		// Remove action from character
		yield return new WaitForEndOfFrame();
		controller.GetComponent<SoulInfo>().canAct = false;
		
		// Enable Cinematic override to prevent camera following
		// Player
		mainCamera.GetComponent<WorldControls>().cinematicOverride = true;
		
		activated = true;
		
		yield return new WaitForSeconds(duration + durationToWait);

		duration = durationToStart;
		fromPos = endAt;
		toPos = startAt;
		
				
		yield return new WaitForSeconds(duration);
		
		activated = false;
		
		// Re-enable Cinematic override
		mainCamera.GetComponent<WorldControls>().cinematicOverride = false;
		// Return action to character
		controller.GetComponent<SoulInfo>().canAct = true;
	}

And here is how I am calling it in the Update:

// Update is called once per frame
	void Update () {
		if(activated){
			//Interpolate from one point to another
			mainCamera.transform.position = Vector3.Lerp(fromPos, toPos, Time.time/duration);
		}
	}

It seems to make perfectly logical sense to me, but does not behave how I’d like.

It DOES move from start to end absolutely fine at the right speed and DOES wait the right amount of seconds at that point.

It DOES NOT get past the second WaitForSeconds()

I tested it with Debug.Log and it stops working as soon as add:

 duration = durationToStart;
    fromPos = endAt;
    toPos = startAt;

before the second WaitForSeconds.

Anyone know what’s going on?

Why don’t you use iTween?

You can do the movement you want in one code line:

iTween.MoveTo(camera.gameObject, destPos, moveTime);