Reputation: 83
I attached an audiosource to a gameobject and in a script attached to the played I put :
void OnCollisionEnter2D (Collision2D col) {
if (col.gameObject.tag == "tag") {
col.gameObject.GetComponent<AudioSource>().Play();
Destroy(col.gameObject);
GetComponent<Score>().score += 1;
}
}
In order to play a sound when there is a collision. But it's not working and I wonder where is the mistake. Thanks for the help. Everything but the sound is working it's not a collision nor a volume problem.
Upvotes: 0
Views: 64
Reputation: 3919
The problem is that you are destroying the GameObject that is playing the audio immediatly after you play it. Consider attaching the AudioSource to a other GameObject instead.
Upvotes: 0