์บ๋ฆญํฐ๊ฐ ์ค๋ธ์ ํธ์ ์ํธ์์ฉํ๋ ์คํฌ๋ฆฝํธ์ ๋๋ค
ํด๋น ์ค๋ธ์ ํธ๋ myName๊ณผ ์ด๋ฆ์ด ๋์ผํ ์คํฌ๋ฆฝํธ๋ฅผ ๊ฐ์ง๊ณ ์๊ณ ํญ์ Interaction ํจ์๊ฐ ์์ต๋๋ค.
์บ๋ฆญํฐ๊ฐ GetComponent๋ก myName๊ณผ ์ด๋ฆ์ด ๊ฐ์ ์คํฌ๋ฆฝํธ๋ฅผ ๋ถ๋ฅด๊ณ ์ถ์๋ฐ ์ < > ์์ ๋ฌธ์์ด์ ๋ฃ๋๋ฒ์ ๋ชฐ๋ผ์... ์ค๋ฅ๊ฐ ๋ฉ๋๋ค
๋ฐฉ๋ฒ์ด ์์๊น์?
string className = "MyComponent"; Type componentType = Type.GetType(className); object component = gameObject.GetComponent(componentType);
Type์ด๋ผ๋ ํ์ ์ด ์๋์??
System.type
using Sytem;
์ฝ๋ ๋ฐ๋ผ์จ๋ดค๋๋ฐ ํ์ ์ด์์ผ๋ฉด ์ฐํด๋ฆญํด์ ๋น ๋ฅธ์์ ๋ฐ ๋ฆฌํํ ๋ง ํ์ธํด๋ณด์
์ ํด๊ฒฐํ์ต๋๋ค ๊ฐ์ฌํฉ๋๋ค