2
votes

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

1
Do you have an active AudioListener in your scene? - Jacek Przemieniecki
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? - Heisenbug

1 Answers

2
votes
  • 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.