|
|
¾î¶² ±â´ÉÀÇ ¿ÜºÎ¿¡¼ Á¤ÀÇµÈ ¾î¶² º¯¼ö´Â ¸â¹ö º¯¼ö·Î Á¤ÀǵȴÙ. º¯¼öµéÀº ÅëÇÕ ³»¿¡¼ °¨µ¶°üÀ» ÅëÇØ Á¢±ÙÇÒ ¼ö ÀÖ´Ù. ¸â¹ö º¯¼ö¿¡ ÀúÀåµÈ ¾î¶² °ªÀº ¶ÇÇÑ ÇÁ·ÎÁ§Æ®¿Í ÇÔ²² ÀÚµ¿ÀûÀ¸·Î ÀúÀåµÈ´Ù. 1. JavaScript var memberVariable = 0.0; 2. C# using UnityEngine; using System.Collections; public class example : MonoBehaviour { public float memberVariable = 0.0F; } The above variable will show up as a numeric property called "Member Variable" in the inspector. If you set the type of a variable to a component type (i.e. Transform, Rigidbody, Collider, any script name, etc.) then you can set them by dragging game objects onto the value in the inspector. 1. JavaScript var enemy : Transform; function Update() { if ( Vector3.Distance( enemy.position, transform.position ) < 10 ) print("I sense the enemy is near!"); } 2. C# using UnityEngine; using System.Collections; public class example : MonoBehaviour { public Transform enemy; void Update() { if (Vector3.Distance(enemy.position, transform.position) < 10) print("I sense the enemy is near!"); } } ´ç½ÅÀº ¶ÇÇÑ ¸¸µé¾î ³¾ ¼ö ÀÖ´Ùprivate member variables. °³ÀÎ ¸â¹ö º¯¼öµéÀº ½ºÅ©¸³Æ® ¿ÜºÎ¿¡¼ º¸ÀÌÁö ¾Ê¾Æµµ µÇ´Â ÀúÀå »óÅ¿¡ ´ëÇØ À¯¿ëÇÏ´Ù. °³ÀÎ ¸â¹ö º¯¼ö´Â µð½ºÅ©¿¡ ÀúÀåµÇÁö ¾ÊÀ¸¸ç, °¨µ¶°üÀÌ ¼öÁ¤ÇÒ ¼ö ¾ø´Ù. ±×µéÀº µð¹ö±× ¸ðµå·Î ¼³Á¤µÉ ¶§ °¨µ¶°ü¿¡°Ô º¸¿©Áø´Ù. ÀÌ°ÍÀº µð¹ö°Å¸¦ ½Ç½Ã°£ ¾÷µ¥ÀÌÆ®ÇÑ °Íó·³ °³ÀÎ º¯¼öµéÀ» »ç¿ëÇϵµ·Ï ÇØÁØ´Ù. 1. JavaScript private var lastCollider : Collider; function OnCollisionEnter(collisionInfo : Collision ) { lastCollider = collisionInfo.collider; } 2. C# using UnityEngine; using System.Collections; public class example : MonoBehaviour { private Collider lastCollider; void OnCollisionEnter(Collision collisionInfo) { lastCollider = collisionInfo.collider; } } Global variables ´ç½ÅÀº Á¤Àû Å°¿öµå¸¦ »ç¿ëÇÏ¿© ±Û·Î¹ú º¯¼ö¸¦ ¸¸µé ¼ö ÀÖ´Ù. ÀÌ°ÍÀº someGlobalÀ̶ó ºÒ¸®´Â ±Û·Î¹ú º¯¼ö¸¦ ¸¸µç´Ù. 1. JavaScript // The static variable in a script named 'TheScriptName.js' static var someGlobal = 5; // You can access it from inside the script like normal variables: print(someGlobal); someGlobal = 1; 2. C# using UnityEngine; using System.Collections; public class example : MonoBehaviour { public static int someGlobal = 5; void Awake() { print(someGlobal); someGlobal = 1; } } ´Ù¸¥ ½ºÅ©¸³Æ®·Î ºÎÅÍ Á¢±ÙÇÏ´Â °ÍÀº ´ç½ÅÀÌ Á¡°ú ±Û·Î¹ú º¯¼ö À̸§À¸·Î µû¶ó¿À´Â ½ºÅ©¸³Æ®ÀÇ À̸§À» »ç¿ëÇؾßÇÑ´Ù.print(TheScriptName.someGlobal); TheScriptName.someGlobal = 10; |