赞
踩
- using System.Collections;
- using System.Collections.Generic;
- using UnityEngine;
-
- public class AudioManager : MonoBehaviour {
- public static AudioManager Instance;
- // Use this for initialization
- public AudioSource bg_music_player;//背景音乐播放
- public AudioSource action_music_player;//音效播放
-
- private void Awake()
- {
- Instance = this;
- }
- void Start () {
-
- }
-
- void Update () {
-
- }
-
- public void PlayBgMusic(string name)
- {
- if (!bg_music_player.isPlaying)
- {
- AudioClip audioClip = Resources.Load<AudioClip>(name);
- bg_music_player.clip = audioClip;
- bg_music_player.Play();
- }
- else
- {
- Debug.LogError("正在播放中不能切换");
- }
-
- }
-
- public void StopBgMusic()
- {
- if (bg_music_player.isPlaying)
- {
- bg_music_player.Stop();
- }
- }
-
- //播放音效
- public void PlayActionSound(string name)
- {
- AudioClip audioClip = Resources.Load<AudioClip>(name);
- action_music_player.PlayOneShot(audioClip);
- }
-
-
- public void StopActionSound(string name)
- {
- action_music_player.Stop();
- }
- }
Copyright © 2003-2013 www.wpsshop.cn 版权所有,并保留所有权利。