AudioRamp

                Never    
C#
       
using UnityEngine;

namespace Darkersmile 
{
	public class EngineAudio : MonoBehaviour 
	{
        [Header("Control")]
        [Range(0, 1)]
        [Tooltip("The actual percentage of the total pitch")]
        public float DesiredPitchPercentage = 0.5f;

        [Header("Settings")]
        [Range(0.01f, 1)]
        [Tooltip("How fast the pitch catches up to the desired volume")]
        public float PitchAcceleration = 0.15f;

        [Tooltip("The minimum and maximum possible pitch")]
        public Vector2 PitchRange = new Vector2(0, 2);

        [Tooltip("Pitch Eval Curve")]
        public AnimationCurve Curve = AnimationCurve.EaseInOut(0, 0, 1, 1);


        [Header("Read Only")]
        [Tooltip("The actual current pitch")]
        [Range(0, 1)]
        public float currentPitchPercentage;

        void Awake()
        {
            _source = GetComponent<AudioSource>();
            currentPitchPercentage = Percentage(_source.pitch, PitchRange.x, PitchRange.y);
        }


        void Update()
        {
            UpdateEngineAudioPitch();

        }

        void UpdateEngineAudioPitch()
        {
            if (currentPitchPercentage > DesiredPitchPercentage)
                currentPitchPercentage -= Time.deltaTime * PitchAcceleration;
            if (currentPitchPercentage < DesiredPitchPercentage)
                currentPitchPercentage += Time.deltaTime * PitchAcceleration;

            _source.pitch = Mathf.Lerp(PitchRange.x, PitchRange.y, Curve.Evaluate(currentPitchPercentage));
        }




        public static float Percentage(float current, float start, float end)
        {
            return (current - start) / (end - start);
        }

        private AudioSource _source;
    }
}

Raw Text