-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathSoundPlayer.cs
More file actions
55 lines (49 loc) · 1.16 KB
/
SoundPlayer.cs
File metadata and controls
55 lines (49 loc) · 1.16 KB
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
using UnityEngine;
using System.Collections;
namespace Assets.Scripts
{
class SoundPlayer : MonoBehaviour
{
public AudioClip[] song;
public bool SFX;
public bool playOnLoad;
public bool loop;
public bool intro;
public int loopSong;
public bool dontDestroy;
void Start()
{
if (playOnLoad)
PlaySong(0);
if (dontDestroy)
DontDestroyOnLoad(this.gameObject);
}
void Update()
{
if (intro && !audio.isPlaying)
{
intro = false;
PlaySong(1);
}
}
public void PlaySong(int index)
{
audio.Stop();
if (SFX)
audio.volume = Data.SfxVol;
else
audio.volume = Data.MusicVol;
audio.loop = loop&&index==loopSong;
audio.clip = song[index];
audio.Play();
}
public void Pause()
{
audio.Pause();
}
public void SetVolume(float vol)
{
audio.volume = vol;
}
}
}