ย ๋งจ ๋ฐ‘์— ์งˆ๋ฌธ ์š”์•ฝ ์žˆ์๋‹ˆ๋‹ค.


์ธํ„ฐ๋„ท ๋ง‰ ๊ฒ€์ƒ‰ํ•˜๋Š”๋ฐ ์–ด๋–ค ๊ณณ์€ ๊ทธ๋ƒฅ

DontDestroyOnLoad()ย ๋ฉ”์„œ๋“œ๋งŒ ์‚ฌ์šฉํ•˜๊ณ 


์–ด๋–ค ๊ณณ์€ static GameManger instance;

void Awake(){

instance = this;

}


์ด๋ ‡๊ฒŒ ์“ฐ๊ณ  ์žˆ๊ณ 


์ œ๊ฐ€ ์ง€๊ธˆ ์“ฐ๊ณ  ์žˆ๋Š” ๊ฑด

ย private static GameManager _instance;

ย  ย 

ย  ย  public static GameManager Instance

ย  ย  {

ย  ย  ย  ย  get

ย  ย  ย  ย  {

ย  ย  ย  ย  ย  ย  .

ย  ย  ย  ย  ย  ย  if (!_instance)

ย  ย  ย  ย  ย  ย  {

ย  ย  ย  ย  ย  ย  ย  ย  _instance = FindObjectOfType(typeof(GameManager)) as GameManager;


ย  ย  ย  ย  ย  ย  ย  ย  if (_instance == null)

ย  ย  ย  ย  ย  ย  ย  ย  ย  ย  Debug.Log("no Singleton obj");

ย  ย  ย  ย  ย  ย  }

ย  ย  ย  ย  ย  ย  return _instance;

ย  ย  ย  ย  }

ย  ย  }


ย  ย private void Awake()

ย  ย  {

ย  ย  ย  ย  Paused = false;

ย  ย  ย  ย 

ย  ย  ย  ย  if (_instance == null)

ย  ย  ย  ย  {

ย  ย  ย  ย  ย  ย  _instance = this;

ย  ย  ย  ย  }

ย  ย  ย ย 

ย  ย  ย  ย  else if (_instance != this)

ย  ย  ย  ย  {

ย  ย  ย  ย  ย  ย  Destroy(gameObject);

ย  ย  ย  ย  }

ย  ย  ย  ย 

ย  ย  ย  ย  DontDestroyOnLoad(gameObject);

ย  ย  }


์ธ๋ฐ ์ฐจ์ด๋Š” ๋ญ”๊ฐ€์š”...?


์งˆ๋ฌธ ์š”์•ฝ :

1.ย  DontDestroyOnLoad(gameObject);๋งŒ ์จ์•ผ๋˜๋‚˜ instance๋ฅผ ์จ์•ผ๋˜๋‚˜

2. instance์“ฐ๋Š” ์ด์œ ๋Š”?

ย