Last active
April 13, 2019 10:24
-
-
Save gkagm2/2bf563255156fadc5a50d04081ffb198 to your computer and use it in GitHub Desktop.
Unity AudioManager.cs singleton Instance
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
using System.Collections; | |
using System.Collections.Generic; | |
using UnityEngine; | |
public class AudioManager : MonoBehaviour { | |
static AudioManager _instance = null; | |
public static AudioManager Instance() | |
{ | |
return _instance; | |
} | |
// Use this for initialization | |
void Start () { | |
if(_instance == null) | |
{ | |
_instance = this; | |
} | |
} | |
// Update is called once per frame | |
void Update () { | |
} | |
public void PlaySfx(AudioClip clip) | |
{ | |
GetComponent<AudioSource>().PlayOneShot(clip); | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
using System.Collections; | |
using System.Collections.Generic; | |
using UnityEngine; | |
public class csAudioManager : MonoBehaviour { | |
public AudioClip clip; | |
public void OnCollisionEnter(Collision collision) | |
{ | |
AudioManager.Instance().PlaySfx(clip); | |
Destroy(this.gameObject); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment