Advertisement
Skrzypczako

soundmanager

Jun 9th, 2021
50
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.10 KB | None | 0 0
  1. using System.Collections;
  2. using System.Collections.Generic;
  3. using UnityEngine;
  4. [RequireComponent(typeof(AudioSource))]
  5.  
  6. public class SoundManager : MonoBehaviour
  7. {
  8.  
  9. public static SoundManager instance;
  10.  
  11. public AudioClip click;
  12. public AudioClip walking;
  13. public AudioClip jump;
  14.  
  15. public AudioSource effectsSource;
  16.  
  17. public bool muted;
  18. private AudioSource audioSource;
  19.  
  20. private void Awake()
  21. {
  22. if (instance == null)
  23. {
  24. instance = this;
  25. DontDestroyOnLoad(gameObject);
  26. }
  27. else
  28. {
  29. Destroy(gameObject);
  30. }
  31.  
  32. audioSource = GetComponent<AudioSource>();
  33. }
  34.  
  35. public void ToggleMuted()
  36. {
  37. muted = !muted;
  38.  
  39. audioSource.mute = muted;
  40. }
  41.  
  42. public bool GetMuted()
  43. {
  44. return muted;
  45. }
  46.  
  47. public void PlayOnceJump()
  48. {
  49. if (muted) return;
  50. effectsSource.PlayOneShot(jump, 1f);
  51. }
  52.  
  53. public void PlayOnceClick()
  54. {
  55. if (muted) return;
  56. effectsSource.PlayOneShot(click, 1f);
  57. }
  58. }
  59.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement