x


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.

more ▼

asked Mar 22 '10 at 10:39 PM

The BOOM gravatar image

The BOOM
283 20 26 39

When I instantiate a prefab with an audio source component it loads fine and the audio plays. How are you loading your prefab?

Mar 23 '10 at 02:23 AM straydogstrut

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.

Mar 28 '10 at 04:29 PM The BOOM
(comments are locked)
10|3000 characters needed characters left

2 answers: sort voted first

Well, regarding the Audio.play() try audio.PlayOneShot(NameOfWhatYouWantToPlay).

more ▼

answered Mar 23 '10 at 01:12 AM

karl_ gravatar image

karl_
2.5k 41 53 70

(comments are locked)
10|3000 characters needed characters left

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

more ▼

answered Jun 15 '10 at 03:53 PM

OpIvy gravatar image

OpIvy
63 3

(comments are locked)
10|3000 characters needed characters left
Your answer
toggle preview:

Up to 2 attachments (including images) can be used with a maximum of 524.3 kB each and 1.0 MB total.

Follow this question

By Email:

Once you sign in you will be able to subscribe for any updates here

By RSS:

Answers

Answers and Comments

Topics:

x1059
x176
x29

asked: Mar 22 '10 at 10:39 PM

Seen: 3041 times

Last Updated: Mar 22 '10 at 10:39 PM