-
Notifications
You must be signed in to change notification settings - Fork 1
/
AudioController.cs
61 lines (52 loc) · 1.38 KB
/
AudioController.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class AudioController : MonoBehaviour {
// Soundtrack and respective difficulty level triggers
public AudioClip[] soundtracks;
public AudioClip gameOverClip;
int[] scoreTrigger = { 0, 0, 1, 2 };
int currTrack = 0;
bool paused = false;
public AudioSource backgroundMusic;
// Use this for initialization
void Start () {
backgroundMusic.clip = soundtracks[0];
backgroundMusic.Play();
}
public void Pause() {
if (!paused) {
backgroundMusic.Pause();
paused = true;
}
}
public void Resume() {
if (paused) {
backgroundMusic.Play();
paused = false;
}
}
public void SwitchMusic(int level) {
int newTrack = scoreTrigger[level];
if (newTrack == currTrack) return;
currTrack = newTrack;
backgroundMusic.Stop();
backgroundMusic.clip = soundtracks[newTrack];
backgroundMusic.Play();
}
public void Restart() {
currTrack = 0;
paused = false;
backgroundMusic.Stop();
backgroundMusic.clip = soundtracks[0];
backgroundMusic.loop = true;
backgroundMusic.Play();
}
public void GameOver() {
currTrack = -1;
backgroundMusic.Stop();
backgroundMusic.clip = gameOverClip;
backgroundMusic.loop = false;
backgroundMusic.Play();
}
}