How to play some audio and sound files by clicking some buttons respectively in Unity

Create a script in your Unity editor and name it MyAudioManager.cs

Then paste this code:

using System.Collections;
using System.Collections.Generic;
using UnityEngine;

public class MyAudioManager : MonoBehaviour
	public AudioClip one;
	public AudioClip two;
	public AudioClip three;
	AudioSource audio;
    // Start is called before the first frame update
    void Start()
        audio = GetComponent<AudioSource>();

	public void PlaySound(string audioName){
			case "one" :
				audio.clip = one;
			case "two" :
				audio.clip = two;
			case "three" :
				audio.clip = three;

And watch the video for more steps:

Then you will know how to play multiple audio sound files by clicking some buttons on Unity 😀


Leave a Reply

Your email address will not be published. Required fields are marked *