当前位置:   article > 正文

Unity3D --//简单的音频播放脚本_unity控制音频开始脚本

unity控制音频开始脚本
  1. using System.Collections;
  2. using System.Collections.Generic;
  3. using UnityEngine;
  4. public class AudioManager : MonoBehaviour {
  5. public static AudioManager Instance;
  6. // Use this for initialization
  7. public AudioSource bg_music_player;//背景音乐播放
  8. public AudioSource action_music_player;//音效播放
  9. private void Awake()
  10. {
  11. Instance = this;
  12. }
  13. void Start () {
  14. }
  15. void Update () {
  16. }
  17. public void PlayBgMusic(string name)
  18. {
  19. if (!bg_music_player.isPlaying)
  20. {
  21. AudioClip audioClip = Resources.Load<AudioClip>(name);
  22. bg_music_player.clip = audioClip;
  23. bg_music_player.Play();
  24. }
  25. else
  26. {
  27. Debug.LogError("正在播放中不能切换");
  28. }
  29. }
  30. public void StopBgMusic()
  31. {
  32. if (bg_music_player.isPlaying)
  33. {
  34. bg_music_player.Stop();
  35. }
  36. }
  37. //播放音效
  38. public void PlayActionSound(string name)
  39. {
  40. AudioClip audioClip = Resources.Load<AudioClip>(name);
  41. action_music_player.PlayOneShot(audioClip);
  42. }
  43. public void StopActionSound(string name)
  44. {
  45. action_music_player.Stop();
  46. }
  47. }

 

声明:本文内容由网友自发贡献,转载请注明出处:【wpsshop博客】
推荐阅读
相关标签
  

闽ICP备14008679号