Sound doesn't play before destruction(even after delaying the destroy func)
Hello
I'm trying to play an audio before the player dies, nothing interesting about this. However as far as I understood from other posts, the audio doesn't play because object is destroyed first. So I tried to delay the destruction of the object but still there is no sound. If I put a breakpoint to the Destroy(plyr, ac,length) line, so program stops there and bingo! The sound comes. So I assume it is an issue related with timing of the destruction however the code below doesn't work properly without that breakpoint. I appreciate any help thanks!
plyr = GameObject.FindGameObjectWithTag("Player");
asource = plyr.GetComponent ();
ac = (AudioClip)Resources.Load("explosion_player", typeof(AudioClip));
asource.PlayOneShot(ac);
Destroy (plyr, ac.length);
Your answer
![](https://koobas.hobune.stream/wayback/20220612130119im_/https://answers.unity.com/themes/thub/images/avi.jpg)
Follow this Question
Related Questions
Destroy(GameObject) works after 3 attempts 0 Answers
Fix sound delay 6 Answers
Error CS1519 help 1 Answer
Help with Editing Code 0 Answers
Script plays sound at incorrect time 1 Answer