首页 > 其他 > 详细

背景音乐管理器

时间:2014-02-13 05:36:56      阅读:346      评论:0      收藏:0      [点我收藏+]
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

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!