Audio Pitch

I have a nice dive effect to which I want to add a pitch value to the sound; my problem is that the pitch is rather sudden - I need a larger fade value when I pitch; here’s my code:

if( distanceToGround > 20 && euler.x > 18  )
{
    diveEffect.active = true;
    audio.pitch = Mathf.Lerp( 0, 3, 2.5);  
}   
	if( distanceToGround < 1000 && euler.x < 10  )
{
    diveEffect.active = false;
    audio.pitch = Mathf.Lerp( 0, 0.5, 2.5); 

I also tried Matf.Clamp but that didn’t work either.

The problem here is that you don’t use the previous value with the Lerp. Consequently, the Lerp is useless since it will always return the same value.

Consider Lerp to be equivalent to:

Lerp(currentValue, endValue, rate);

Therefore, you need to use something like:

audio.pitch = Mathf.Lerp(audio.pitch, 0.5, 2.5*Time.deltaTime);