Audio mixed, blending on distance ?


I want to get the following effect: In a room is an object, lets say e.g a musical clock that plays a distorted silent melody.
If I move towards this audio source it gets louder and more clear getting rid of those distortions. so the audio source’s volume reacts to distance of the player to the object
My idea was that I could make two soundfiles one clear one distorted and while moving towards the musical clock both files get mixed, blended into one.

player distance from object 90% → audio (distorted) 100% audio (clear) 0% overall audio 10%
player distance from object 50% → audio (distorted) 50% audio (clear) 50% overall audio 50%
player distance from object 10% → audio (distorted) 0% audio (clear) 100% overall audio 90%

I would be very pleased if you could help me out or at least give me some hints (:

Wish you a lovely day!

Sure, you can do this pretty easily – just have two AudioSources, and set the volume on each one based on the player’s distance. You can use something like Mathf.Clamp01((dist-minDist)/(maxDist-minDist)) to convert from a distance to a ratio.

However, if you have Unity Pro, you should also consider using the various audio filter components (e.g. AudioDistortionFilter) instead.