Time.deltaTIme does not work the way it should.

Hello everyone !

I’m trying to make a texture blend to one another in 5 sec when I press space.
I have found a shader that works well on the forum everything goes the way I want but when I’m trying to update it in 5 sec with that code :

var timeLeft = 0.000;
var duration = 0.000;
function Start () {


}

function Update () {
 
    if (Input.GetKeyDown("space")) {
     //   print("space key was pressed in Update");

   
      
        while (duration <= 5) {
            timeLeft += Time.deltaTime;
            duration += Time.deltaTime;
          //  print(timeLeft);
           // print(duration);
            var lerp = Mathf.PingPong (timeLeft, duration) / duration;
            GetComponent.<Renderer>().material.SetFloat( "_Blend", lerp );

        }

    }

    else if (duration >= 5) {

        duration = 0;
    }
        
}

It just change my texture in one frame and I don’t know why, shouldn’t it be doing it in 5sec (as duration has +Time.deltaTime everyframe?).

Thanks in advance

I’ve achieved this by doing a coroutine in C#

here it is if someone needs it :

using UnityEngine;
using System.Collections;

public class coroutine : MonoBehaviour {
    float timeLeft = 0;
    float duration = 0;
    float blending = 5;
    // Use this for initialization
    void Start () {

    }
	
	// Update is called once per frame
	void Update () {
        if(Input.GetKeyDown("space"))
        {
            if (duration >= 5)
            {
                duration = 0;
                StartCoroutine("corout");
            }
            else
            {
                StartCoroutine("corout");
            }
         }
       
    }

    IEnumerator corout()
    {
        while (duration <= 5)
        {
            timeLeft += Time.deltaTime;
            duration += Time.deltaTime;
            print("timeLeft" + timeLeft);
            print("duration" + duration);
            var lerp = Mathf.PingPong(timeLeft, blending) / blending;
            GetComponent<Renderer>().material.SetFloat("_Blend", lerp);
            yield return null;
        }
        
    }

}