It should smooth slowly increase the speed from 0 to 1 then slowly smoothly decrease from 1 to 0 then again from 0 to 1 and so on nonstop.
but what it does now it's just increasing the speed value all the time. and maybe there is a simple way shorter code to do it?
public Animator playerAnimator;
public float speed;
private float t = 0.0f;
private float min = 0;
private float max = 1;
private bool maxed = false;
void Update()
{
if (t == 0)
{
maxed = true;
}
if(t == 1)
{
maxed = false;
}
if(maxed)
{
t += speed * Time.deltaTime;
playerAnimator.SetFloat("Forward", Mathf.Lerp(min, max, t));
}
else
{
t -= speed * Time.deltaTime;
playerAnimator.SetFloat("Forward", Mathf.Lerp(min, max, t));
}
}