I know how to play Sounds by Adding them to Audiosource and then creating script, But what if i have many different type of Characters?

Wouldn’t that mean that I’d have to repeat the long tedious process of dragging the sounds for each one of the characters. Especially i mean tedious since all the character types use the same sounds.

For example i may have 20 types of guys(different 3d model)
they all should use same sounds. Say 30 sounds.

But if i do it with the method above, then i’d have to repeat the dragging of 30 sounds onto the Audiosource pane for each character.

This is the method I"m referring to, I learned it from a Video Tutorial

  1. Add an AudioSource component to your game object
  2. Create a script . just an example. And for now only one sound, but imagine 30 or 100 sounds.

AUdioClip myClip
void start(){

3 Drag the script to the Game object

4 now drag the sound to the variable “my Clip” that appears in the Audio Source part of the inspector of the Game Object

So Yeah this process is cool but imagine i had 30 sounds or 100
and 20 different types of characters to do this process for.

There are several ways to treat with sound in unity.
In your case if you will you the same sound for every character, like a bullet hit sound or a character getting hurt like “Aaaaahh” or whatever…
You can have a an empty game object and add Audio source + drag sound to clip variable.

Create a prefab in you project, and name it for example hitSoundObject, drag your empty GO to your prefab.

In you script,
have a public variable of type GameObject, drag your prefab to this object.
and have an another variable like private GameObject currentSoundObject.

whenever there’s a hit , you will just Instantiate your prefab, note that you have to check the “play automatically” on your audio source component.

I also use a script named “Self Destroy”, where the sound is created and destroys itsels after 1,2,3 seconds, depending on your sound.

If you need more assistance, leave a comment and I can past a code example…

hope it helps