0
\$\begingroup\$

I need to know how to do this in a 2d game when my 2d character approaches a sounding spirit. the sound should increase as you approach it and decrease as you move away from it. for example, it is a radio sprite and makes sounds, and when you approach the radio the sound becomes louder and vice versa.
please help me

\$\endgroup\$
  • 1
    \$\begingroup\$ What technology stack are you using? Unity C#? Java? etc. How do you represent and move your character and spirits so far? How have you tried playing sound so far? \$\endgroup\$ – DMGregory Apr 18 at 14:22
  • \$\begingroup\$ I program in the language c # I interact the character with other objects through tag player scripts. I created this script just to make the music sing when the character enters the collider box public class TrigerSFX : MonoBehaviour { public AudioSource PlaySound; public void OnTriggerEnter2D(Collider2D col) { if (col.gameObject.tag == "Player") { PlaySound.Play(); } } } \$\endgroup\$ – PVGblack Apr 18 at 15:14
  • 2
    \$\begingroup\$ Looks like you're using Unity. You've probably noticed that code is not very legible in a comment. Please edit your question to ensure it contains a complete description of your problem and how you're tackling it so far. \$\endgroup\$ – DMGregory Apr 18 at 15:17
0
\$\begingroup\$

The easiest way to get this behavior is using an Audio listener component attached to your player and an Audio source component attached to whatever you want to be making noise. You may want to remove the Audio listener component attached to the camera when you put one on your player.

| improve this answer | |
\$\endgroup\$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.