The function of the AudioManager is to manage/play sound clips.
The Sound-Class stores all AudioSources (just sounds) in an object so the AudioManager can work with them.
The AudioManager will get instantiated ONLY in the HomeScene (via DoNotDestroy) → so if you don't start from the HomeScene, the AudioManager may not work properly!!!
Make sure to add/remove sounds in the prefab and not in the GameObject → so they get saved directly to the prefab
Add a sound
Paste your AudioFile in the folder: "Assets/Audios".
To add a sound, just go to the AudioManager GameObject Prefab and add a new item to the "sounds-list".
Delete a sound
To delete a sound, just go to the AudioManager GameObject Prefab and delete the item of the "sounds-list".
Play a sound
If you want to play a sound, access the current AudioManager and call the "Play(string name)"-method.
This method searches for a sound by the name and plays it for you.
This easiest way to do this is: FindObjectOfType<AudioManager>().Play(name);
This function will not crash the game if the sound was not found, but cause a warning
The function of the AudioManager is to manage/play sound clips.
The Sound-Class stores all AudioSources (just sounds) in an object so the AudioManager can work with them.
The AudioManager will get instantiated ONLY in the HomeScene (via DoNotDestroy) → so if you don't start from the HomeScene, the AudioManager may not work properly!!!
Make sure to add/remove sounds in the prefab and not in the GameObject → so they get saved directly to the prefab
Add a sound
Paste your AudioFile in the folder: "Assets/Audios".
To add a sound, just go to the AudioManager GameObject Prefab and add a new item to the "sounds-list".
Delete a sound
To delete a sound, just go to the AudioManager GameObject Prefab and delete the item of the "sounds-list".
Play a sound
If you want to play a sound, access the current AudioManager and call the "Play(string name)"-method.
This method searches for a sound by the name and plays it for you.
This easiest way to do this is:
FindObjectOfType<AudioManager>().Play(name);This function will not crash the game if the sound was not found, but cause a warning