AudioMgr.cs 967 B

1234567891011121314151617181920212223242526272829303132333435363738394041424344
  1. using System.Collections;
  2. using System.Collections.Generic;
  3. using UnityEngine;
  4. public class AudioMgr : MonoBehaviour
  5. {
  6. private static AudioMgr _instance;
  7. //µ¥Àû
  8. public static AudioMgr instance
  9. {
  10. get
  11. {
  12. if (_instance == null)
  13. {
  14. GameObject goR = Resources.Load<GameObject>("Prefabs/AudioMgr");
  15. GameObject AudioMgr = Instantiate(goR);
  16. _instance = AudioMgr.AddComponent<AudioMgr>();
  17. }
  18. return _instance;
  19. }
  20. }
  21. private AudioSource music;
  22. private AudioSource sound;
  23. private void Awake()
  24. {
  25. music = transform.Find("Music").GetComponent<AudioSource>();
  26. sound = transform.Find("Sound").GetComponent<AudioSource>();
  27. //Çл»³¡¾°²»Ïú»Ù
  28. DontDestroyOnLoad(this);
  29. }
  30. public void PlayBGM()
  31. {
  32. music.Play();
  33. }
  34. public void PlaySound()
  35. {
  36. sound.Play();
  37. }
  38. }