How to have audio only be heard in a certain radius?

Hi, I’m a sophomore in high school learning Unity and I’m kind of a noob. I’ve made a few games here and there for myself but one thing I don’t know how to work to well with is audio. I have an audio source on a game object that is a campfire. The audio that it is playing is the sound of a crackling fire, but when I play the game, I can hear it from far away. That is the only sound in the game as of right now and it plays as if it’s background music, which I don’t want. I want it to be heard only in a certain radius, say two unity units. I want it to be like real life, where you can hear a sound getting stronger as you get near it. No not neccessarily like a doppler effect, but more like the sound only plays in a sphere or something. I’ll be as clear as possible as log as you can help me. Thank you in advance. No, I do not have any scripts attached to the campfire, but I will script if it’s needed to acheive what I want. Thank you

2 Likes

You need to do three things on Audio Source

  1. Spatial Blend from 2D to 3D.
  2. Volume Rolloff from logarithmic to
    linear.
  3. Set Minimum and Maximum distance.

This video will show how to do this:

Well did you take a look at the documentation?

Just set the Audio to 3D and use AudioSource.maxDistance for the effect of the sound getting louder.

For anyone still having issues, I found that if you do not have an “audio listener” on your player. You will hear all sounds. Make sure you have an audio listener on your player.

thanks solved my issues, my problem was it was 0.995 so not at 3D and this messed with it xD