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.