Simple, lightweight and Easy to use audio system for your own game in Unity Game Engine.
- use the command at your desired download location
git clone https://github.com/mohakdev/Unity-Audio-System.git
- Once installed open the repository folder in Unity
- Drag the Audio System GameObject into your first scene of the game
- Go to Scripts/SoundClips.cs
- Find SoundTypes enum. This is the place where you need to enter all the types of sound you want to play.
- Once added go back to Inspector, Click on AudioSystem GameObject and find Audio List.
- Drag & Drop the sounds you want to play when a certain Sound Type is called.
- Once all the audios are dragged and dropped you will be finished with the installation.
In whichever script you wanna play audio simply add
using RadiantTools.AudioSystem;
Note -> If you are using Assembly Definitions then don't forget to add this assembly as a reference.
Audio Manager -> It controls and manages all the existing audio players. You can make or delete or get audio players using AudioManager.cs
Audio Player -> Basically it controls an audio track. It is nothing but a script attached to a gameobject with AudioSource
as a component. You can play Audio using a Audio Player. By default 2 AudioTracks exists which are Music and SoundSFX. Music Track has settings to make audio loop forever. While Ideally you should use SoundSFX to play one shot sounds like button click or victory sound etc. For more sounds like for example walking, car engine sound or something it is ideal to make your own custom audio track using Audio Manager.
AudioPlayer soundSFX = AudioManager.Instance.GetAudioPlayer("SoundSFX");
soundSFX.PlayAudioOnce(SoundTypes.AudioOne);
//Using Custom Player to Play One Shot Sounds
AudioPlayer customPlayer = AudioManager.Instance.MakeAudioPlayer("Test");
customPlayer.PlayAudioOnce(SoundTypes.AudioOne);
To Play continuous sounds like walking , car engine use a custom track and manage it settings that way
AudioPlayer customPlayer = AudioManager.Instance.MakeAudioPlayer("Test");
customPlayer.SetAudioClip(customPlayer.GetAudioClip(SoundTypes.AudioTwo));
customPlayer.SetAudioSettings(loop: true);
customPlayer.PlayAudio();
//Changing settings of audio as well
customPlayer.SetAudioSettings(loop: true, startOnPlay : true, volume : 1, pitch : 1);
This code is licensed under MIT License which you can read here