본문 바로가기
{Programing}/Game Engine

Unity - 매니저 클래스를 위한 singleton

by 탱타로케이 2020. 6. 9.
public class GameManager : MonoBehaviour {
 
    public static GameManager instance;
 
    public int level;
 
    void Awake () {
        instance = this;
    }
    
}

 

static 객체를 선언하고 awake함수에서 this로 할당해주면 바로 singleton이 됨.

instance 는 항상 public이어야만 한다.

씬 내에 하나만 존재해야만 하는 객체를 singleton으로 선언한다.

'{Programing} > Game Engine' 카테고리의 다른 글

Unity - 모바일 해상도 고정 대응.  (0) 2020.06.12
Unity - Particle  (0) 2020.06.12
Unity - GameObject Find  (0) 2020.06.09
Unity - Scene Change  (0) 2020.06.09
Unreal Engine 4 - UE_LOG  (0) 2020.03.04

댓글