I used to have a script that would get my player prefab to play a 2D sound whenever a specific object was instantiated. I recently updated to Unity4.1 (previous version was 3.5.x) and now my script doesn’t work, and I constantly get an error saying
Can not play a disabled audio source
UnityEngine.AudioSource:PlayOneShot(AudioClip)
I did do some research and it’s apparently because it won’t play a sound from a prefab but I can’t seem to find another way of doing this. This is my script on the Instantiated object.
var explosionSound : AudioClip;
var audioSource : AudioSource;
function Start(){
audio.enabled = true;
audioSource.PlayOneShot(explosionSound);
}
Where audioSource is my player prefab, and I have 2 slightly modified versions of that prefab in my scene (player 1 and player 2)
What is the best possible way to get my sound played? Any help would be greatly appreciated.
My first quess is either the gameobject this script is attached to does not have an AudioSource or it is not enabled through the checkbox in the Inspector
– hexagonius