campfire/Assets/Scripts/AudioMaster.cs

27 lines
785 B
C#
Raw Normal View History

2020-04-19 01:12:29 +02:00
using UnityEngine;
using UnityEngine.Audio;
public class AudioMaster : MonoBehaviour {
public GameState GameState;
public AudioMixer Mixer;
public AudioMixerSnapshot PlayingSnapshot;
public AudioMixerSnapshot PausedSnapshot;
public AudioMixerSnapshot GameoverSnapshot;
public float TransitionDuration;
void Update() {
float[] Weights = {
GameState.Current == State.Playing ? 1 : 0,
GameState.Current == State.Paused ? 1 : 0,
GameState.Current == State.GameOver ? 1 : 0,
};
AudioMixerSnapshot[] Snapshots = {
PlayingSnapshot,
PausedSnapshot,
GameoverSnapshot,
};
Mixer.TransitionToSnapshots(Snapshots, Weights, TransitionDuration);
}
}