- Home /
Add Audio Source to a Prefab
When I load a prefab, it doesn't load the audio source that is connected to it, so it doesn't play when I want it too.
Also, on a slightly related note, when I use Audio.play() in a script, it plays every single audio source attached to an object/prefab in the scene/assets.
Help please? Thanks in advance.
When I instantiate a prefab with an audio source component it loads fine and the audio plays. How are you loading your prefab?
I have this: var explode : AudioClip; in the code, and then I drag and drop the file I want (which is in wav format) into the slot on the inspector.
Answer by karl_ · Mar 23, 2010 at 01:12 AM
Well, regarding the Audio.play() try audio.PlayOneShot(NameOfWhatYouWantToPlay).
Answer by OpIvy · Jun 15, 2010 at 03:53 PM
Regarding the first problem - make sure you added an AudioSource component to the prefab that contains AudioClip member with the linked asset (that's what got me...)
Your answer
![](https://koobas.hobune.stream/wayback/20220612123935im_/https://answers.unity.com/themes/thub/images/avi.jpg)
Follow this Question
Related Questions
Function Update play sound once 1 Answer
Audio Distortion effects? 0 Answers
2nd Audio Clip Not Playing 0 Answers
Need help with audio files causing unity to freeze 0 Answers
How Do I Get This To Play Sound? 0 Answers