Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System.Collections;
- using System.Collections.Generic;
- using UnityEngine;
- [RequireComponent(typeof(AudioSource))]
- public class SoundManager : MonoBehaviour
- {
- public static SoundManager instance;
- public AudioClip click;
- public AudioClip walking;
- public AudioClip jump;
- public AudioSource effectsSource;
- public bool muted;
- private AudioSource audioSource;
- private void Awake()
- {
- if (instance == null)
- {
- instance = this;
- DontDestroyOnLoad(gameObject);
- }
- else
- {
- Destroy(gameObject);
- }
- audioSource = GetComponent<AudioSource>();
- }
- public void ToggleMuted()
- {
- muted = !muted;
- audioSource.mute = muted;
- }
- public bool GetMuted()
- {
- return muted;
- }
- public void PlayOnceJump()
- {
- if (muted) return;
- effectsSource.PlayOneShot(jump, 1f);
- }
- public void PlayOnceClick()
- {
- if (muted) return;
- effectsSource.PlayOneShot(click, 1f);
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement