°ÔÀÓ±â¼úÀÚ·á
¤ýÀÛ¼ºÀÚ ¹èÀçȯ
¤ýÀÛ¼ºÀÏ 2011-09-22 (¸ñ) 11:08
¤ýȨÆäÀÌÁö http://ugame.tu.ac.kr/webboard
¤ýÃßõ: 0  ¤ýÁ¶È¸: 897      
¤ýIP: 210.xxx.56
Unity3D-Overview: Accessing Other Components
±¸¼º ¿ä¼Ò°¡ °ÔÀÓ ¿ÀºêÁ§Æ® °³Ã¼¿¡ ÷ºÎµË´Ï´Ù. Ä«¸Þ¶ó ¿ÀºêÁ§Æ®¾È¿¡ 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().Translate(0, 1, 0);
}
}

º¯È¯°ú 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();
}
}


  0
2500
    N     ºÐ·ù     Á¦¸ñ    ±Û¾´ÀÌ ÀÛ¼ºÀÏ Á¶È¸
14 ÀÏ¹Ý Unity3D-Overview: The most important classes(3) ¹èÀçȯ 2011-09-22 1166
13 ÀÏ¹Ý Unity3D-Overview: The most important classes(2) ¹èÀçȯ 2011-09-22 1078
12 ÀÏ¹Ý Unity3D-Overview: The most important classes(1) ¹èÀçȯ 2011-09-22 953
11 ÀÏ¹Ý Unity3D-Overview: Writing Scripts in C# ¹èÀçȯ 2011-09-22 1926
10 ÀÏ¹Ý Unity3D-Overview: Coroutines & Yield ¹èÀçȯ 2011-09-22 1046
9 ÀÏ¹Ý UnIty3D-Overview: Instantiate ¹èÀçȯ 2011-09-22 870
8 ÀÏ¹Ý Unity3D-Overview: Member Variables & Global Variables ¹èÀçȯ 2011-09-22 944
7 ÀÏ¹Ý Unity3D-Overview: Vectors ¹èÀçȯ 2011-09-22 928
6 ÀÏ¹Ý Unity3D-Overview: Accessing Other Game Objects ¹èÀçȯ 2011-09-22 988
5 ÀÏ¹Ý Unity3D-Overview: Accessing Other Components ¹èÀçȯ 2011-09-22 897
4 ÀÏ¹Ý Unity3D-Overview: Keeping Track of Time ¹èÀçȯ 2011-09-22 931
3 ÀÏ¹Ý Unity3D-Overview: Common Operations ¹èÀçȯ 2011-09-22 879
2 ÀÏ¹Ý ³Í ÇÒ ¼ö ÀÖ¾î °­»ó¿¡ 2011-03-22 907
1 ÀÏ¹Ý ÀϾ ±è±¤¼® 2011-03-22 872
123