27 lines
785 B
C#
27 lines
785 B
C#
|
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);
|
|||
|
}
|
|||
|
}
|