public class DontDestroy<T> : MonoBehaviour where T : DontDestroy<T>
{
private static T instance;
private void Awake()
{
if (instance == null)
instance = this as T;
else
Destroy(gameObject);
DontDestroyOnLoad(gameObject);
}
}
'Unity' 카테고리의 다른 글
[Unity] static 클래스를 통한 상수 관리 (1) | 2020.10.19 |
---|---|
[Unity/Event] 변수 변경시 정해진 이벤트 호출하기 (0) | 2020.10.19 |
[Unity/UI] Image로 Fade In, Fade Out 효과 (2) | 2020.10.05 |
[Unity] Generic Singleton (0) | 2020.10.05 |
[Unity/UI] 유저가 정해진 버튼만 클릭할 수 있게 하기 (0) | 2020.08.26 |