Reputation: 103
I am looking for some way of making it so that the player can only hear the sounds as they get close to an object. In other words, a sound that only plays within a certain radius, or proximity sound, if this makes any sense.
If anyone knows of a way to do this in unity, any advice would be helpful!
Thanks,
Callum
Upvotes: 0
Views: 8064
Reputation: 486
You can use Unity's built-in 3D audio features to achieve that effect. Simply, if you attach an AudioSource to your desired object (the source of sound), and put the 3d audio sample you'd like to use in it as an AudioClip, you can edit its min/max distance and rolloff values accordingly to set the hearing radius. Note that, in that case you might want to attach your AudioListener to the player object instead, as the distance calculation will be done between the source and the listener.
Alternatively, you could write a small script to cast a sphere to find if the transform of the audio source is inside and change the volume etc. accordingly. Of course, you need to add colliders to your game objects in that case. See: http://docs.unity3d.com/ScriptReference/Physics.SphereCast.html
Upvotes: 3