- Home /
I fixed it myself.
Audio not playing on TriggerEnter (Pic Included)
Hi, i'm trying to make it so when my player character enters a gems trigger it plays a sound, destroys the gem, then sets the playerpref to 1. But I can't get the sound to play?
Can someone take a look at this and tell me why the sound might not be playing.
Answer by Stardog · Feb 11, 2015 at 01:06 AM
Try adding a Rigidbody2D (isKinematic set to true) to the Gem.
yes. It does get destory and the playerpref is set to 1. It just doesn't play the sound.
Probably. I'll move the sound from the gem to the player.
Answer by t-schulz · Mar 02, 2015 at 12:03 PM
if you play a sound and delete the object, the sound will NOT be played. Delay the Destroy() and the sound will play!
Thanks to chariot for the hint!
Answer by Digital-Phantom · Mar 02, 2015 at 12:54 PM
Use a coroutine for your sound. In some cases on trigger enter only actually has an effect for that brief moment the trigger is entered.
You could try using OnTriggerStay instead (depending on your needs)
Personally I would just add something like -
start coroutine PlayTheSound() (add this line to your OntriggerEnter event)
Then make another function -
void PlayTheSound()
{
//**insert your sounds line of code here**
}
Follow this Question
Related Questions
Sound wont play when triggered (javascript) 1 Answer
PlayOneShot in OnTriggerEnter function (Unity 5) 0 Answers
My soundclip is noisy? 2 Answers
How to fix my reload sound? 0 Answers
Need help with AudioSources 1 Answer