void Awake() { if (instance == null) { instance = this; sources = GetComponentsInChildren <AudioSource>(); } else { DestroyObject(gameObject); } }
void Awake() { if (ins == null) { ins = this; } else if (ins_ != this) { //전것존재 -> 또다른것 -> 삭제. 이후는 실행안됨(Start, OnEnable)... //Debug.Log ("또생성? 음... 삭제(지금것)"); Destroy(gameObject); return; } DontDestroyOnLoad(gameObject); }
public float highPitchRange = 1.05f; //The highest a sound effect will be randomly pitched. void Awake() { //Check if there is already an instance of SoundManager if (instance == null) { //if not, set it to this. instance = this; } //If instance already exists: else if (instance != this) { //Destroy this, this enforces our singleton pattern so there can only be one instance of SoundManager. Destroy(gameObject); } //Set SoundManager to DontDestroyOnLoad so that it won't be destroyed when reloading our scene. DontDestroyOnLoad(gameObject); }