I have a character with a bunch of different attacks + sound effects in Unity.
One way to architect this is to create a single AudioSource, and then set the AudioSource.clip to a specific sfx each time an attack happens. E.g.:
playerAudio.clip = laserSfx;
playerAudio.PlayOneShot();
(Where playerAudio
is an AudioSource
, and laserSfx
is an AudioClip
loaded at runtime)
Another method is to have child game objects with their own AudioSources, so when I do attack A, I can do something like AttackA.GetComponent<AudioSource>().Play()
Is there a preferred way of doing this in Unity? Considering performance impacts and such.