How would you start another lerp based off of a condition of a current lerp?

I’m trying to monitor the state of a current lerp, and then start another lerp mid lerp of the first lerp!

:stuck_out_tongue:

(sorry just like typing lerp!)

But seriously, If I have a Mathf.Lerp making a number go from 1-0, I’m trying to start another lerp when that number reaches say the mid point (.5). But for some reason, I’m not getting the results I’m after.

Here’s my code;

if ( lives == 0 )
	{
		var t: 		float = 0.0f;
		var on: 	float = 1.0f;
		var off:	float = 0.0f;
		
		while(t < 1)
	   	{
        	t += Time.deltaTime / panelFadeOutTime;
        	panel.GetComponent(UIPanel).alpha = Mathf.Lerp (on, off, t);
        	yield;
        	
        }
        
 	}
 	if (panel.GetComponent(UIPanel).alpha <= .8)
    {
      	var r:		float = 0.0f;
        	        	
       	while(r < 1)
		{
      		r += Time.deltaTime / panelFadeOutTime;
       		panelLose.GetComponent(UIPanel).alpha = Mathf.Lerp (off, on, r);
       		yield;
       	}
    }

These lerps are controlling an alpha attribute of two different sprites, I’m simply trying to fade one down and fade one up just before the first one fades down.

What’s happening with this current code is one will fade down completely, and then one fades up.

thanks for reading!

I would declare t and r at the start of the script and set them to 0. Increment the timers, then zero them when you want to reset the lerps.

Your Lerps are inside while loops which is why one finishes before the other. A while loop will complete until the condition is false before continuing with the rest of the script. Remove the whiles and use an if to add running conditions instead.