์ด๋ ๊ฐ์ฒด๊ฐ AAA_Script๋ฅผ ๊ฐ์ง๊ณ ์๋ค๊ณ ํ ๋
...
public AAA_Script test;
test= FindObjectOfType<AAA_Script>(); // AAA_Script ์๋ฃํ์ธ๋ฐ gameObject๋ฅผ ๋ฐํํ๋ FindObjectOfType๋ฅผ ์ด๋ป๊ฒ ์ฌ์ฉํ๊ฑด๊ฐ์?
์ด๋ ๊ฐ์ฒด๊ฐ AAA_Script๋ฅผ ๊ฐ์ง๊ณ ์๋ค๊ณ ํ ๋
...
public AAA_Script test;
test= FindObjectOfType<AAA_Script>(); // AAA_Script ์๋ฃํ์ธ๋ฐ gameObject๋ฅผ ๋ฐํํ๋ FindObjectOfType๋ฅผ ์ด๋ป๊ฒ ์ฌ์ฉํ๊ฑด๊ฐ์?
ํด๋น ๋๊ธ์ ์ญ์ ๋์์ต๋๋ค.
์!! ๊ทธ์๊ฐ์ ๋ชปํ๋ค์ ๋ต๋ณ ๊ฐ์ฌํฉ๋๋ค!!
์ง๋ฌธ์ด ์กฐ๊ธ ์ง์ ๋ถํ๊ฒ๊ฐ์์ ๋ฐ๊ฟจ์์ต๋๋ค....ใ ใ ์ ๊ฐ ์ง๋ฌธ์ ์๋ชป ๋ฐ๊พธ๋ฉด์ ํํธ๊ฐ ์๋๊ฐ๊ฒ ๊ฐ์๋ฐ, ํน์ ์ด ๋ป์ด ๋ง์๊น์?1) script๋ AAA_Scriptํ์ ๋ฐ์๊ฒ ๋ง๋ค (findof...๋ก) 2) script๋ AAA_Scriptํ์ด์ง๋ง, ์์๋ฐ๊ธฐ๋๋ฌธ์ gameObject ํ๋กํผํฐ๊ฐ ์๋ค 3) ๊ทธ๋ฌ๋ฏ๋ก script.transform.position = this.transform.position;๊ฐ ๊ฐ๋ฅํ๋ค script.transform.position = this.transform.position;๊ทธ๋ ๋ค๋ฉด ์ด ๋ฌธ์ฅ์ดscript.gameObject.transform.position = this.transform.position;์ ๊ฐ์ ๋ป์ผ๊น์????
์๋ก ๊ฐ์ต๋๋ค.
Monobehaviour๋ Component์ ์์์ด๊ณ (์ ํํ๋ Component์ ์์๋ฐ์ Behaviour์ ์์) Componentํ์ ์ transform๊ณผ gameObject variables๋ฅผ ์ ๊ณตํฉ๋๋ค
์ ๊ฐ ์ ๋ํฐ์ C#์ ์ ํ์ง ์ผ๋ง ์๋ผ์ ๋ฐฉ๊ธ Behaviour์ ์ฐพ์๋ดค์ต๋๋ค. ์ด๋ฅผ ์์ํ๊ณ ์์ผ๋ ์คํฌ๋ฆฝํธ๋ฅผ ๊ฐ์ง ๊ฐ์ฒด์ ๋ค๋ฅธ ์ปดํฌ๋ํธ(transform ๋ฑ)์ ์ ๊ทผ์ํ ์ ์๋ค๋๊ฒ ๊ฐ์๋ฐ, ๋ง์๊น์??
FindObjectOfType์ UnityEngine namespace์ ์ํด์๋ ๋ฉ์๋๋ฅผ ํธ์ถํ๊ฑฐ๊ณ , AAA_Script๋์ ์๋ฌด ์ฐ๊ด์ด ์์ต๋๋ค.
ํ์ฌ ํธ์ถํ๊ณ ์๋ ์ฝ๋์์ Monohehaviour๋ฅผ ์์๋ฐ์๊ธฐ๋๋ฌธ์ ์ฌ์ฉ์ด ๊ฐ๋ฅํ๊ฑฐ๊ณ ๋น์ฐํ FindObjectOfType์ Unity Objectํ์ ์ผ๋ก ์บ์คํ ๊ฐ๋ฅํ๊ฒ ์ ๋ค๋ฆญ์ ๋ค์ด๊ฐ์ผํ๋ฏ๋ก AAA_Script๋ Mono๋ฅผ ์์๋ฐ์๊ฒ ์ฃ .
์ ์ ํํ๊ฒ ์ดํดํ๊ฒ ๊ฐ์ต๋๋ค!! ๋ต๋ณ ์ ๋ง ๊ฐ์ฌ๋๋ฆฝ๋๋ค! ์๊ฐ์ ์๋ชป ํ์๋ค์....