- Home /
Question by
RandomUser123 · Sep 21, 2014 at 04:21 PM ·
audioclipsource
Problem playing a sound
I have this code here:
public AudioClip pop;
if(collide.gameObject.tag == "bullet")
{
audio.PlayOneShot(pop);
Destroy (collide.gameObject);
Destroy (gameObject);
}
I want the sound to play when my bullet collides with the enemy, but so far I get nothing, my enemies all have Audio Sources and the audioClip is added to them in the project view. I have other sounds working, just having trouble with this one, anyone know why that might be?
Comment
Answer by no9rg · Sep 21, 2014 at 11:37 PM
Did you try not to destroy gameObject immediately? audio.PlayOneShot can't play if the gameObject doesn't exist.
Your answer
Follow this Question
Related Questions
Do I have to create an audio source component to play a sound from script? 2 Answers
How to stop an Audio Clip without an Audio Source? 1 Answer
Audio Script 1 Answer
Guys i need help with audio! 0 Answers
Choose from 2 audio Sources 2 Answers