-
Notifications
You must be signed in to change notification settings - Fork 16
Sound
To manage audio, you first need to go through AudioManager
. This component should be mounted in the Persistent Scene according to the scene-flow.
-
The properties of AudioManger are:
- Player Prefab : Prefab of AudioPlayer, Each sound that needs to be played will be performed by an AudioPlayer.
- Audio Asset: ScriptableObject contains all Audio Data
To use this we will first need to create an AudioData via menu Create
> Pancake
> AudioData
You can also use Ctrl + D
to duplicate an existing audio data but this time its Id will not be automatically regenerated so you need to regenerate it by right clicking on it.
-
There are two main types of Type:
SFX
andMusic
. -
You can play multiple sounds at the same time through the same
AudioData
by adding elements toGroups
, each group will have a list of clips, the clip to be played will be selected based onSequence Mode
. -
Each group will have a
Cooldown To Play
option to avoid playing too many similar sounds at once -
Next we will declare an
AudioId
property
[SerializeField, AudioPickup] private AudioId bgm;
- Now we can select
AudioData
through Inspector, If you don't seeAudioData
in the drop-down window, it means thatAudioData
has not been added toAudioAsset
, you can add it using theAddToAudioAsset
button in thatAudioData
or theLoadAll
button to add all availableAudioData
inAudioAsset
bgm.Play();
bgm.Play().QuietOthers(0.5f, 0.2f, 1f);
bgm.Stop();
bgm.Pause();
bgm.Resume();
AudioStatic.StopAll();
AudioStatic.StopAllByType(EAudioType.Sfx);