private void Update() { // Find what proportion of the engine's power is being used. var enginePowerProportion = Mathf.InverseLerp(0, m_Propellers.getMaxPower(), m_Propellers.getPower()); // Set the engine's pitch to be proportional to the engine's current power. m_EngineSoundSource.pitch = Mathf.Lerp(m_EngineMinThrottlePitch, m_EngineMaxThrottlePitch, enginePowerProportion); // Increase the engine's pitch by an amount proportional to the aeroplane's forward speed. // (this makes the pitch increase when going into a dive!) m_EngineSoundSource.pitch += m_Rigidbody.velocity.magnitude * m_EngineFwdSpeedMultiplier; // Set the engine's volume to be proportional to the engine's current power. m_EngineSoundSource.volume = Mathf.InverseLerp(0, m_Propellers.getMaxPower() * m_AdvancedSetttings.engineMasterVolume, m_Propellers.getPower()); // Set the wind's pitch and volume to be proportional to the aeroplane's forward speed. float planeSpeed = m_Rigidbody.velocity.magnitude; m_WindSoundSource.pitch = m_WindBasePitch + planeSpeed * m_WindSpeedPitchFactor; m_WindSoundSource.volume = Mathf.InverseLerp(0, m_WindMaxSpeedVolume, planeSpeed) * m_AdvancedSetttings.windMasterVolume; }