|
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 |
using
UnityEngine;using
System.Collections;/// <summary>/// 背景音乐管理器/// </summary>public
class BgMusic : MonoBehaviour { public
static AudioSource bgMusic;//播放器 void
Start () { if(bgMusic == null){ bgMusic = transform.Find("BgMusic").gameObject.AddComponent<AudioSource>(); } } /// <summary> /// 播放背景音乐 /// </summary> public
static void PlayMusic(string
levelPath){ //根据关卡,获取不同的音频路径 string
path = null; switch(levelPath){ case
"MainMenu": path = "Sound/BgMusic/menu";break; case
"Village": path = "Sound/BgMusic/village";break; case
"Cemetery": path = "Sound/BgMusic/danger";break; case
"Grave": path = "Sound/BgMusic/outdoor";break; } AudioClip clip = Resources.Load(path) as
AudioClip; bgMusic.clip = clip; bgMusic.volume = UISetting.BgMusicVolume; bgMusic.loop = true; bgMusic.Play(); } /// <summary> /// 设置音量大小 /// </summary> public
static void SetVolume(float
volume){ bgMusic.volume = volume; }} |
原文:http://www.cnblogs.com/xiao-wei-wei/p/3546653.html