What are the advantages of using
AudioSource.PlayClipAtPoint(fireSound, transform.position);
Instead of adding an audio source to the Laser GameObject and tick ‘Play on Awake’?
What are the advantages of using
AudioSource.PlayClipAtPoint(fireSound, transform.position);
Instead of adding an audio source to the Laser GameObject and tick ‘Play on Awake’?
Using PlayClipAtPoint creates a new AudioSource object which is then automatically disposed of once the clip has finished playing.
If you had this attached to your laser, as soon as the laser was destroyed, the audio source would be also, and your sound effect would stop abruptly.
See also;
I take from that: unless you can guarrantee the AudioSource can finish playing before your object (which the AudioSource is attached to) is destroyed it could lead to unexpected behaviour.
Thank you for the answer.
Exactly. You could have an entirely separate object for managing all of tge sound effects and fire messages back to play on event etc, but there are some limitations with the number of simultaneous clips that can be played at once with the same audio source.
Definitely at this stage I would recommend the PlayClipAtPoint method.
that is what I figure out as well