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.
Author by
y2k
Updated on June 04, 2022Comments
-
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:
and like I said, just the 2 lines in the C# file
-
Jacek Przemieniecki almost 11 yearsDo you have an active AudioListener in your scene?
-
Heisenbug almost 11 yearsIt 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 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.