Plugin for playing 2D sounds and music in games based on Unity.
<< How to use | Install | Download >>
- Create in Assets/SoundAndMusicSystem/Scripts/SoundsAndMusicDB.cs new enums items for SoundType, MusicType.
namespace SoundAndMusic
{
public enum SoundType
{
None = 0,
PlayerAttack = 1
}
public enum MusicType
{
None = 0,
TownMusic = 1
}
}
- Attach to Assets/SoundAndMusicSystem/Resources/SoundsAndMusicDB.asset some sounds and music with enum items.
- Add to game scene Assets/SoundAndMusicSystem/Prefabs/SoundAndMusicController.prefab (better where the game is loading). You can set up audio sources count, sound and music volumes in inspector.
- Use API SoundAndMusicController for playing sounds and music in your custom scripts.
using SoundAndMusic;
using UnityEngine;
public class SomeController : MonoBehaviour
{
private void Start()
{
PlayBackgroudMusic();
PlaySomeSound();
}
private void PlayBackgroudMusic()
{
SoundAndMusicController.Instance.PlayBackgroundMusic(MusicType.TownMusic);
}
private void PlaySomeSound()
{
SoundAndMusicController.Instance.PlaySoundAudio(SoundType.PlayerAttack);
}
}
- Also you can use another public API for volume setting (SetSoundVolumeAudioSources, SetVolumeBackGroundMusic) and for stopping all sounds/music (StopAllAudioSource).
Download SoundAndMusicSystem.unitypackage
and using UnityPackageManager.