728x90 반응형 싱글톤1 [유니티] DontDestroyOnLoad 싱글톤 패턴 사용법 using UnityEngine; public class StartManager : MonoBehaviour { public static StartManager instance = null; void Awake() { // SoundManager 인스턴스가 이미 있는지 확인, 이 상태로 설정 if (instance == null) instance = this; // 인스턴스가 이미 있는 경우 오브젝트 제거 else if (instance != this) Destroy(gameObject); // 이렇게 하면 다음 scene으로 넘어가도 오브젝트가 사라지지 않습니다. DontDestroyOnLoad(gameObject); } } 2021. 6. 22. 이전 1 다음 728x90 반응형