Doing something wrong with lerp?

I’m relatively experienced with C#. I’ve been using it for software development and stuff like that, but I’ve never used it in Unity and that’s probably why I don’t what I’m doing wrong. Basically, I’m trying to lerp a the speed of an object to make it accelerate, and I’m using Lerp. I followed the tutorials, and I’ve experimented with it a lot, and looked for other answers, but something here is wrong, and I have no idea what it is.

void testFunction()
	{
		float minSpeed = 0.0f;
		float maxSpeed = 10.0f;
		float currentSpeed = 0.0f;
		byte lerpSpeedMult = 10;

		if(Input.GetKey("w")) 
		{
			currentSpeed = Mathf.Lerp(minSpeed, maxSpeed, Time.deltaTime * lerpSpeedMult);
			transform.Translate (Vector3.forward * currentSpeed * Time.deltaTime); 
			print (currentSpeed);
		}
	}

I’m calling testFunction in Update, but I seriously have no idea what I’m doing wrong here. I’m using minSpeed as the “from” parameter of lerp, and maxSpeed as the “to” parameter, and making the current value of that lerp to be the currentSpeed, then I’m moving the ship by currentSpeed, but currentSpeed constantly remains zero, as well as all other variables. I know that I’m doing something that any kind of Unity veteran would spot, but yet again, I’ve never used C# in Unity before.

the third argument of lerp represents the progress between the two values. What you are doing here is supply the same value on every frame (very small value as well) so there will be no progress.

What you want to do is to accumulate the rate (Time.deltaTime * lerpSpeedMult) into a variable on each frame and then supply this variable to the lerp.

Here is how to do this in a coroutine - the reason to do that is because then you can keep the value of local variables, which is important for keeping the progress. Otherwise the progress would have to be a class variable

    void Start()
    {
        StartCoroutine(lerp());
    }

    private IEnumerator lerp()
    {
        float minSpeed = 0.0f;
        float maxSpeed = 100.0f;
        float currentSpeed = 1.0f;
        float lerpSpeedMult = 1.0f;

        float progress = 0f;


        //You can change this loop so the coroutine stops when you reached the max speed
        while(true)
        {
            currentSpeed = Mathf.Lerp(minSpeed, maxSpeed, progress);
            progress += lerpSpeedMult * Time.deltaTime;
            yield return null;
        }
    }