how do i put many audio clips in audio source in inspector?

I have a player and when he hits certain enemys it makes different sounds

I added audio source and added 1 clip which was easy and it does play but I want different sounds on different enemys
and since theres only 1 slot in audio source in inspector??

how do I add more clips to audio source? so he can play on different collisions different sounds or is this strictly done in code only?

2d

using UnityEngine;
using System.Collections;

[RequireComponent(typeof(AudioSource))]
public class fishdedd : MonoBehaviour {

	public AudioClip pop1;
	public AudioClip boing;
	AudioSource audio;

		 Animator anim;                    //reference to the animator component
	void Start()
		{
		audio = GetComponent<AudioSource>();
			//GetComponent<Rigidbody2D>().velocity = new Vector2 (forwardSpeed, 0);
		}

		void OnCollisionEnter2D(Collision2D other)
	{
		
if (other.gameObject.tag == "Player" || other.gameObject.tag == "Wall" ) 
{
	// do something when we collide with "enemy1" OR "enemy2"
	anim.Play("fishded");
	anim.SetTrigger("Die");
	GetComponent<AudioSource> ().Play ();
		audio.PlayOneShot(pop1, 0.7F);
}
else if (other.gameObject.tag == "tr" || other.gameObject.tag == "tr" ) 
{
	// do something else when we collide with "enemy3" OR "enemy4"
			anim.Play("fishded");
			anim.SetTrigger("Die");
			GetComponent<AudioSource> ().Play ();
			audio.PlayOneShot(boing, 0.7F);

}

	}
}

2 Answers

2

If you’re using variables for the audio clips you just put “public AudioClip one, two, three, etc”
If you want audio sources on a game object you click “Add component” Audio Source then five it a sound like normal. To access the sounds you do audio = GetComponents(); and to play them do audio[0].Play(); for sound 1 and sound 2 will be audio[1] and so on…

so for each sound I would have to add another audio component?

In my game I’m using empty game objects as children of the player game object to attach different audio sources and then access them in a script attached to the player game objects object.