-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathBGMControl.cs
58 lines (51 loc) · 1.29 KB
/
BGMControl.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
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using System.Threading;
public class BGMControl : MonoBehaviour
{
[SerializeField]
private AudioClip MainMenuBGM;
[SerializeField]
private AudioClip IngameBGM;
AudioSource audioSource;
private void Awake()
{
DontDestroyOnLoad(transform.gameObject);
audioSource = gameObject.GetComponent<AudioSource>();
// set and play music
audioSource.clip = MainMenuBGM;
audioSource.loop = true;
audioSource.Play();
}
public void ChangeBGMToMainMenu()
{
if(audioSource.clip == MainMenuBGM)
{
return;
}
else
{
// stop current BGM
audioSource.Stop();
//Change and play MainMenu BGM
audioSource.clip = MainMenuBGM;
audioSource.Play();
}
}
public void ChangeBGMToIngame()
{
if (audioSource.clip == IngameBGM)
{
return;
}
else
{
// stop current BGM
audioSource.Stop();
//Change and play Ingame BGM
audioSource.clip = IngameBGM;
audioSource.Play();
}
}
}