Unity AUDIO MANAGER Tutorial

Video Statistics and Information

Video
Captions Word Cloud
Reddit Comments
Captions
Hi everyone. In this video we will add music and sound effect to the game. We will create a simple Audio Manager Script and we will be able to access this code  from anywhere and play the sound effects. We will also learn how to turn the music on and  off and adjust the volume from the interface. Ok! let's start.  When we start the game in current status , as you see there is no sound in the game. Here are the sounds we will use in the  game. We have 1 music and 4 sound effects. I will create a script named Sound. And open it. This script will only keep the sound name and AudioClip. Back to unity and create a gameobject named Audio Manager. Then add a script  named Audio Manager. And open the script. I create two arrays from sound class  named MusicSounds and sfxSounds.  Back to unity, and add the sounds to the arrays.  I will create 2 objects for audioSource.   After that i will drag and  drop the objects to the slots.  Open the Audio Manager script again.  I will create a method called  PlayMusic to play the music.  I will call this method with the  name of the sound i want to play.  I'm looking for the music I want  to play in the musicSounds array.  If There is no music with the name I'm  looking for, Return “Sound Not found”  If there is, i want it to play the sound. I write similar codes to play sound effects. You can look at other methods you can use to  control AudioSource from the unity Document. I will create a static instance of this  code to easily access it from anywhere.  I want the background music  to play when the game starts.  Ok ! back to unity, and start the game.  Nice! as you can see the  background music is playing.  We haven't included the sound effects yet. Let's take a quick look at Audio Source Component. Mute sets the volume 0.  When enable loop , the sound plays repeatedly. You can change volume of the music. Let's call sound effects from anywhere.  I will call the jump sound effect  from where the jump code is.  Star collect sound effect, mission completed sound effect, and Game Over sound effect. Back to unity, and test it . Ok! sound effects playing.  I want to stop the background music  after the mission is completed.  Nice! better this way.  Let's control the sound using this interface.  Back to the Audio Manager script.  I will write code to be able to turn the  sound on and off and change the volume.  Back to unity. I created a  simple sound control panel. I will create a Script named UIController to  access the audio manager script from this panel.  And open it.  This script is ready, back to unity again.  I will assign the methods  to the buttons on the panel.  Let’s start the game again.  As you can see our sound control panel is working.  I hope the video useful for you. For more such videos, please don't forget to subscribe and like. Thanks for watching, see you in the next video.
Info
Channel: Rehope Games
Views: 42,015
Rating: undefined out of 5
Keywords: unity audio manager, Rehope Games, soundin unity, unity 2d audio manager, unity adudio source, unity audioclip
Id: rdX7nhH6jdM
Channel Id: undefined
Length: 8min 20sec (500 seconds)
Published: Sat Aug 20 2022
Related Videos
Note
Please note that this website is currently a work in progress! Lots of interesting data and statistics to come.