This Unity package was created in Unity Engine v. 2021.3.14f1. It should be used in another version without any error.
- Clone the repository to any place in your computer. There is a Unity Package file in Unity-Simple-Audio-Manager\Assets\AudioManagerByOzzysDen\AudioManagerByOzzysDen.unitypackage.
- Open your Unity project or create a new one. Go to Assets/Import Package/Custom Package on the top navigation menu and import AudioManagerByOzzysDen.unitypackage to your project.
- Package is in your project now.
- In the Assets folder you'll find a Prefabs folder (AudioManagerByOzzysDen\Prefabs). Simply drag AudioManager prefab to your Hierarchy on your scene.
- If you want to use same AudioManager in all of your scenes tick DontDestroy on the prefab. This will make the prefab Singleton pattern. If you want to make it a Singleton I recommend putting the AudioManager in your starting scene only.
- You'll find another prefab in the same directory called AudioPlayer. This prefab has the AudioSource component, which is responsible for playing any Audio in your game. And it is pooled to save memory and resources. This means an instance of AudioPlayer will be created anytime there is no any empty (not playing) AudioPlayer prefab exists under AudioManager. Once a AudioPlayer is created it won't be destroyed, any of them will be used repeatedly.
- There is AudioFiles ScriptableObject called Audio Data in Assets\AudioManagerByOzzysDen directory. Here you have to set your audio clip files in the list.
- This asset was intended to play Sound FX but you also use it to play game music as well. You just have to tick isLoop to play the game music in a loop. There will be a pseudo random Music Player I will share in the future. I'll pass the link here as soon as it is ready.
- Finally, there is a PoolSize variable on the AudioManager. You can set the initial pool size according to your project's scale. Then on the start manager will create defined number of AudioPlayer prefab under AudioManager in the Hierarchy (default is 5).