|
|
±¸¼º ¿ä¼Ò°¡ °ÔÀÓ ¿ÀºêÁ§Æ® °³Ã¼¿¡ ÷ºÎµË´Ï´Ù. Ä«¸Þ¶ó ¿ÀºêÁ§Æ®¾È¿¡ Camera¸¦ ³ÖÀ¸¸ç Renderer ±¸¼º ¿ä¼Ò¸¦ ºÙÀÌ´Â °ÍÀº ȸ鿡 Ç¥ÇöÇÏ°Ô²û ÇÏ´Â °ÍÀÔ´Ï´Ù. ¸ðµç ½ºÅ©¸³Æ®´Â ÀÌ¿Í°°ÀÌ °ÔÀÓ¿ÀºêÁ§Æ®¿¡ ¿¬°áµÉ¼ö ÀÖ´Â ±¸¼º¿ä¼Ò ÀÔ´Ï´Ù. °¡Àå ÀϹÝÀûÀÎ ±¸¼º¿ä¼Ò´Â ´Ü¼øÇÑ º¯¼ö Áý´Üó·³ ¿µÇâ¹Þ±â ½±½À´Ï´Ù. Component Accessible as Transform transform Rigidbody rigidbody Renderer renderer Camera camera (only on camera objects) Light light (only on light objects) Animation animation Collider collider ... etc. ¹Ì¸® Á¤ÀÇµÈ ¸â¹ö º¯¼öÀÇ Àüü ¸ñ·ÏÀ» º¸·Á¸é Component, Behaviour ¹× MonoBehaviour Ŭ·¡½º¿¡ ´ëÇÑ ¼³¸í¼¸¦ ÂüÁ¶ÇϽʽÿÀ. °ÔÀÓÀÇ °³Ã¼¸¦ °¡Á® ¿À ´ç½ÅÀÌ ¿øÇÏ´Â À¯ÇüÀÇ ±¸¼º ¿ä¼Ò°¡¾ø´Â °æ¿ì, À§ÀÇ º¯¼ö´Â null·Î ¼³Á¤µË´Ï´Ù. °ÔÀÓ ¿ÀºêÁ§Æ®¿¡ ¿¬°áµÈ ¸ðµç ±¸¼º¿ä¼Ò¿Í ½ºÅ©¸³Æ®´Â GetComponentÀ» ÅëÇØ Á¢±Ù µÉ¼ö ÀÖ½À´Ï´Ù. 1. JavaScript transform.Translate(0, 1, 0); // is equivalent to GetComponent(Transform).Translate(0, 1, 0); 2.C# using UnityEngine; using System.Collections; public class example : MonoBehaviour { void Awake() { transform.Translate(0, 1, 0); GetComponent } } º¯È¯°ú Transform»çÀÌ°¡ ´Ù¸¥ °æ¿ìÀÓÀ» Âü°íÇÕ´Ï´Ù. ÀüÀÚ´Â º¯¼öÀÌ°í(¼Ò¹®ÀÚ), ÈÄÀڴ Ŭ·¡½º ¶Ç´Â ½ºÅ©¸³Æ® À̸§(´ë¹®ÀÚ)ÀÔ´Ï´Ù. ÀÌ °æ¿ì Â÷À̴ Ŭ·¡½º ¹× ½ºÅ©¸³Æ® À̸§ÀÇ º¯¼ö¸¦ Â÷º°È ½ÃÅ°´Â °ÍÀÌ´Ù. ¿ì¸®°¡ ¹è¿î °ÍÀ» Àû¿ëÇÒ ¶§, ¿ì¸®´Â GetComponent¸¦ »ç¿ëÇÏ¿© °°Àº °ÔÀÓ °³Ã¼¿¡ ¿¬°áµÈ ¾î´À ½ºÅ©¸³Æ®³ª ³»Àå ±¸¼º¿ä¼Ò¸¦ ãÀ»¼ö ÀÖ´Ù. ´ÙÀ½ ¿¹Á¦ ÀÛ¾÷À» ¸¸µé±â À§Çؼ ´ç½ÅÀº DoSomething ±â´ÉÀ» Æ÷ÇÔÇÏ´Â OtherScript¶ó ºÒ¸®´Â ½ºÅ©¸³Æ®¸¦ °¡Á®¾ß¸¸ ÇÑ´Ù. OtherScript ½ºÅ©¸³Æ®´Â ´ÙÀ½ ½ºÅ©¸³Æ®·Î¼ °°Àº °ÔÀÓ °³Ã¼¿¡ ¿¬°áµÇ¾îÁ®¾ß ÇÑ´Ù. 1. JavaScript // ÀÌ°ÍÀº °ÔÀÓ¿ÀºêÁ§Æ®¿¡¼ OtherScript¶ó°í ºÒ¸®´Â ½ºÅ©¸³Æ®¸¦ ã½À´Ï´Ù // ±×¸®°í °Å±â¼ DoSomethingÀ» È£ÃâÇÕ´Ï´Ù. function Update () { var otherScript = GetComponent(OtherScript); otherScript.DoSomething(); } 2. C# using UnityEngine; using System.Collections; public class example : MonoBehaviour { void Update() { System.Object otherScript = GetComponent otherScript.DoSomething(); } } |