123456789101112131415161718192021222324252627282930313233 |
- using System.Net.NetworkInformation;
- using UnityEngine;
- /* Home场景全局控制音效播放
- */
- public class HomeSoundEffectController: MonoBehaviour
- {
- public static HomeSoundEffectController Instance;
- //音效相关
- public AudioSource audioSource;
- public AudioClip[] soundEffect;
- void Awake()
- {
- // 单例模式,确保只有一个GlobalSoundManager
- if (Instance == null)
- {
- Instance = this;
- DontDestroyOnLoad(gameObject);
- }
- else
- {
- Destroy(gameObject);
- }
- }
- public void PlaySoundEffect(int id)
- {
- audioSource.PlayOneShot(soundEffect[id]);
- }
- }
|