Often with three days useful that our sound appears to be coming from a particular place. I walk away, not sure how clear it'll be on the recording, but I walk away, I can no longer hear the sound of the fans. Walking walk towards them gets louder and louder. Again, you've got run away. This appears to none. So let's have a look at the code for that.
When we load it in our environment, we saved the fans in an array. So initially we set a volume to zero and then we have a for each method of the fans array. Which will get each fan in turn, we calculate the distance from the player object to the fan. And we set a temporary volume which is between one and zero based on the distance divided by 1000. And if the current temporary volume is greater than our stored temporary Well, our stored volume, then we set our volume to be our current temporary volume. And then at the end of going through all the fans, we've got a volume based on the nearest of those three fans.
And we set our fan volume to that level. And that allows us as we walking around to hear the fans ramp up in volume as we approach them, and as we run away from them, the volume will disappear virtually to zero