How to play sound only at a certain distance?

Options

I have Audio Source. On certain events, the sound is played through the function:

[PunRPC] private void PlaySound() {

   GetComponent<AudioSource>().PlayOneShot(shootSound);

}

And then this function is called via

photonView.RPC(nameof(PlaySound), RpcTarget.AllBufferedViaServer);

And here's the problem: If you use this method, then the sound will be played simultaneously for all players, throughout the game map, but it needs to be played at a certain distance.

If you use this function without RPC, then everything seems to work, but then this sound is not synchronized.

In the sound settings, I made the minimum distance 1, and the maximum 20.

Best Answer

  • 5XFQjRNxi8uHS3b
    Options

    This is very stupid, but it turns out I just forgot to change the Spatial Blend. Problem solved. sorry for the stupid question

Answers

  • 5XFQjRNxi8uHS3b
    Options

    This is very stupid, but it turns out I just forgot to change the Spatial Blend. Problem solved. sorry for the stupid question

  • Tobias
    Options

    Glad you found it. No worries, this happens :)