Skip to content

ThirteeNov

My personal blog about coding and internet

Menu
  • About me
  • About Zofia Kreasi
  • Cart
  • Checkout
  • Making an airplane game from scratch in Unity
  • My account
  • Privacy Policy
  • Privacy Policy – zkLeaderboard
  • Sample Page
  • Shop
  • Tutorials on Learning JavaScript
  • ZKAccounts – Privacy Policy
Menu

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

Posted on April 9, 2021April 16, 2021 by Habibie

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){
		switch(audioName){
			case "one" :
				audio.clip = one;
				break;
			case "two" :
				audio.clip = two;
				break;
			case "three" :
				audio.clip = three;
				break;
		}
		audio.Play();
	}
	
}

And watch the video for more steps:

Then you will know how to play multiple audio sound files by clicking some buttons on Unity ๐Ÿ˜€

Post Views: 252
ciihuy2020

Welcome!

  • My YouTube Channel
  • My GitHub Page
  • About me

Categories

  • 3DVista
  • Android
  • Apache
  • C#
  • Cordova
  • Electron & Node JS
  • HTML5, CSS & JavaScript
  • iOS
  • Let's Make Unity Games
  • Misc
  • Photoshop
  • PHP
  • Python
  • Uncategorized
  • Unity
  • WordPress

Recent Posts

  • Make objects like wires and cables easily in Unity using Ciihuy Curved Mesh
  • [SOLVED] Canโ€™t Add Custom Domain to Blogger After Losing CNAME Verification
  • iOS App Icon Generator by CiihuyCom
  • Advanced Blinking Marker Script to show objects position in your game canvas
  • Ciihuy Images Merger โ€“ Fast & Easy Online Image Combiner
© 2025 ThirteeNov | Powered by Superbs Personal Blog theme