y2k
y2k

Reputation: 65996

Unity3d AudioClip played with AudioSource not working properly

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

Upvotes: 2

Views: 14984

Answers (1)

Jorjon
Jorjon

Reputation: 5434

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

Upvotes: 2

Related Questions