123456789101112131415161718192021222324252627282930313233 |
- using UnityEngine;
- /* WalkDogs场景,音乐游戏控制音效播放
- * 本代码挂在Player上
- */
- public class SoundGameEffectController: MonoBehaviour
- {
- public static SoundGameEffectController Instance;
- //音效相关
- public AudioSource audioSource;
- public AudioClip[] soundEffect;
- void Awake()
- {
- // 单例模式,确保只有一个GlobalSoundManager
- if (Instance == null)
- {
- Instance = this;
- //DontDestroyOnLoad(gameObject); // 必须关掉否则会导致原场景destroy不能执行
- }
- else
- {
- Destroy(gameObject);
- }
- }
- public void PlaySoundEffect(int id)
- {
- audioSource.PlayOneShot(soundEffect[id]);
- }
- }
|