AudioManager.cs 2.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788
  1. using System.Collections;
  2. using System.Collections.Generic;
  3. using UnityEngine;
  4. namespace DuckHunter
  5. {
  6. public class AudioManager : MonoBehaviour
  7. {
  8. private static AudioManager _Instance;
  9. public static AudioManager Instance
  10. {
  11. get
  12. {
  13. if (!_Instance) new GameObject(typeof(AudioManager).Name).AddComponent<AudioManager>();
  14. return _Instance;
  15. }
  16. }
  17. void Awake()
  18. {
  19. _Instance = this;
  20. }
  21. void OnDestroy()
  22. {
  23. if (_Instance == this) _Instance = null;
  24. }
  25. public void PlayGunShoot(GameObject target)
  26. {
  27. PlayAudio("Audios/gun_shoot", GetAudioSource(target));
  28. }
  29. public void PlayShoot(GameObject target)
  30. {
  31. PlayAudio("DuckHunter/Audios/Shoot", GetAudioSource(target));
  32. }
  33. public void PlayDuckHit(GameObject target)
  34. {
  35. PlayAudio("DuckHunter/Audios/DuckHit", GetAudioSource(target));
  36. }
  37. public void PlayDogTaunt(GameObject target)
  38. {
  39. PlayAudio("DuckHunter/Audios/DogTaunt", GetAudioSource(target));
  40. }
  41. public void PlayDogHappy(GameObject target)
  42. {
  43. PlayAudio("DuckHunter/Audios/DogHappy", GetAudioSource(target));
  44. }
  45. public void PlayGameStart()
  46. {
  47. PlayAudio("DuckHunter/Audios/GameStart", null);
  48. }
  49. public void PlayGameOver()
  50. {
  51. PlayAudio("DuckHunter/Audios/GameOver", null);
  52. }
  53. public void PlayGamePass()
  54. {
  55. PlayAudio("DuckHunter/Audios/GamePass", null);
  56. }
  57. public void PlayFullScore()
  58. {
  59. PlayAudio("DuckHunter/Audios/FullScore", null);
  60. }
  61. public void PlayBtn()
  62. {
  63. AudioMgr.ins.PlayBtn();
  64. }
  65. private void PlayAudio(string audioPath, AudioSource audioSource)
  66. {
  67. AudioMgr.ins.Play(audioPath, audioSource);
  68. }
  69. private AudioSource GetAudioSource(GameObject target)
  70. {
  71. if (target == null) return null;
  72. return AudioMgr.GetAudioSource(target);
  73. }
  74. }
  75. }