Unity3d AudioClip played with AudioSource not working properly

14,753
  • Check that there is a AudioListener in the scene, probably attached to the Camera.
  • Try using the second argument on the PlayOneShot function, to indicate the volume.
  • Remember that having and AudioListener in the same GameObject containing the AudioSource doesn't work (for some reason).
  • If all fails, try playing the sound from another Component, which should only have the code for playing the sound.
Share:
14,753
y2k
Author by

y2k

Updated on June 04, 2022

Comments

  • y2k
    y2k almost 2 years

    So I did (in Unity editor):

    GameObject -> Create Empty

    the I dragged my Avatar.cs (the main player animation MonoBehaviour) onto the gamefile.

    Inside Avatar.cs I added:

    public AudioClip audioClipJump;

    and

    // this is where the jump animation gets played
    audio.PlayOneShot(audioClipJump);
    

    Back in Unity editor, I see the component Audio Clip Jump inside GameObject.Avatar, and I drag and dropped the .wav file onto it.

    Then I go into the game, and the jump animation plays, but I have no sound :(

    here is a screenshot of the Unity editor:

    enter image description here

    and like I said, just the 2 lines in the C# file

    • Jacek Przemieniecki
      Jacek Przemieniecki almost 11 years
      Do you have an active AudioListener in your scene?
    • Heisenbug
      Heisenbug almost 11 years
      It should work. Are you using 3D sound? If that's the case check max distance parameter under 3d audio settings and the location of the source relative to the audio listener. Also, have you got an audio listener somewhere?is it active?
  • SanSolo
    SanSolo over 8 years
    /* AudioListener in the same GameObject containing the AudioSource doesn't work */ thanks. Solved my problem. However, in later versions, that is not a problem.