ºÇ½ª¹¹¿·¡§ orika_ex_miyako 2022ǯ06·î20Æü(·î) 17:54:56ÍúÎò
¡¡¤³¤³¤Ç¤Ï¡¢¥¹¥¯¥ê¥×¥È¤òÍøÍѤ·¤Æ¡¢¥³¥é¥¤¥À¡¼¤Î¥ª¥ó¥ª¥ÕÀÚ¤êÂؤ¨¥Æ¥¹¥È¤ò¹Ô¤¤¤Þ¤¹¡£
¡¡¥³¥é¥¤¥À¡¼¤Ï¥ª¥Ö¥¸¥§¥¯¥È¤Ë¾×ÆÍÍѤÎÅö¤¿¤êÉôʬ¤òÍ¿¤¨¤Þ¤¹¡£
¥³¥é¥¤¥À¡¼¤ò»ý¤Ä¥ª¥Ö¥¸¥§¥¯¥ÈƱ»Î¤¬¤Ö¤Ä¤«¤ë¤È¡¢¤½¤³¤Ç¾×Æͤ¬È¯À¸¤·¤Þ¤¹¡£¡Ê¤¤¤ï¤æ¤ë¡¢Åö¤¿¤êȽÄê¤È¸Æ¤Ð¤ì¤ë¤â¤Î¤Ç¤¹¡£¡Ë
¡¡
¡¡¤³¤Îµ¡Ç½¤Ï¥²¡¼¥à¥ª¥Ö¥¸¥§¥¯¥È¤Ë¥¢¥¿¥Ã¥Á¤µ¤ì¤Æ¤¤¤ë³Æ¥³¥é¥¤¥À¡¼·Ï¤Î¥³¥ó¥Ý¡¼¥Í¥ó¥È¤Ë¤è¤Ã¤ÆÉÕÍ¿¤µ¤ì¤Þ¤¹¡£
¡¡º£²ó¤Î³Ø½¬¤Ç¤Ï¡¢¥¹¥¯¥ê¥×¥È¤òÍøÍѤ·¤Æ¡¢¥³¥é¥¤¥À¡¼¥³¥ó¥Ý¡¼¥Í¥ó¥È¤Î¥¹¥¤¥Ã¥Á¤Î¥ª¥ó¥ª¥Õ¤òÀÚ¤êÂؤ¨¤ëÀ©¸æ¤ò¼ÂÁõ¤·¡¢À©¸æ¤Ç¤¤Æ¤¤¤ë¤«¤ò¥Æ¥¹¥È¤·¤Þ¤¹¡£
¡¡¤½¤ì¤Ç¤ÏÀè¤Û¤É¤ÎRendererTest¤È¤ª¤Ê¤¸¤è¤¦¤Ë¡¢ProjectsÆâ¤ÎAsset ¢ª Scripts ¤ò¥À¥Ö¥ë¥¯¥ê¥Ã¥¯¤·¤Æ³«¤
¤½¤ÎÃæ¤Ç Create ¢ª C# Script¤òÁªÂò¤·¤Þ¤¹¡£Ì¾Á°¤ÏColliderTest¤Ë¤·¤Þ¤¹¡£
¡¡ColliderTest¥Õ¥¡¥¤¥ë¤ò¥À¥Ö¥ë¥¯¥ê¥Ã¥¯¤·¤ÆVisual Studio¤ò³«¤¤¤Æ¡¢¥³¡¼¥É¤ò½ñ¤¤¤Æ¤¤¤¤Þ¤·¤ç¤¦¡£
using System.Collections; using System.Collections.Generic; using UnityEngine; /// <summary> /// ¥³¥é¥¤¥À¡¼¤Î¥Æ¥¹¥ÈÍÑ¥¯¥é¥¹ /// ¥³¥ó¥Ý¡¼¥Í¥ó¥È¤Î¼èÆÀ¤È¥ª¥ó¡¿¥ª¥Õ¡¢¥³¥ó¥Ý¡¼¥Í¥ó¥È¤Î»ý¤Ä¥×¥í¥Ñ¥Æ¥£¤ÎÊѹ¹¤ò¹Ô¤¦ /// </summary> public class ColliderTest : MonoBehaviour { [Header("¥³¥é¥¤¥À¡¼¡ÊÀÜ¿¨È½Äê¡Ë¤Î¥ª¥ó¥ª¥ÕÍÑ")] public BoxCollider boxCollider; void Start() { } void Update() { // ¥Ü¥¿¥ó¤ò²¡¤¹ÅÙ¤ËBoxCollider¥³¥ó¥Ý¡¼¥Í¥ó¥È¤Î¾õÂÖ¤ò¥ª¥ó¡¦¥ª¥ÕÀÚ¤êÂؤ¨¤ë if (Input.GetKeyDown(KeyCode.A)) { // [ÊÑ¿ô̾.enabled]¤Ç¸½ºß¤Î¥³¥ó¥Ý¡¼¥Í¥ó¥È¤Î¾õÂÖ¤ò³Îǧ¤Ç¤¤ë¡£true¤Ê¤é¥ª¥ó¤Î¾õÂÖ if (boxCollider.enabled == true) { // ¥ª¥Õ¤ËÀÚ¤êÂؤ¨¤ë boxCollider.enabled = false; } else { // if¤Î¾ò·ï¤Ç¤Ê¤¤¤Ê¤é¡¢¤³¤Á¤é¤Î½èÍý¤ò¼Â¹Ô = false¤Î¾ì¹ç boxCollider.enabled = true; } } } }
¡¡¥³¡¼¥É¤ò½ñ¤½ª¤ï¤Ã¤¿¤é¡¢Æɤßľ¤¹¤¯¤»¤ò¤Ä¤±¤Þ¤·¤ç¤¦¡£
¡¡¥¹¥¯¥ê¥×¥È¤ò¥»¡¼¥Ö(ctrl + Shift + s ¥¡¼)¤·¡¢¥³¥ó¥Ñ¥¤¥ë¥¨¥é¡¼¤¬¤Ê¤±¤ì¤Ð¡¢¤³¤Î¥Õ¥¡¥¤¥ë¤âCube¥ª¥Ö¥¸¥§¥¯¥È¤Ë¥¢¥¿¥Ã¥Á¤·¤Þ¤·¤ç¤¦¡£
¥¢¥¿¥Ã¥Á¸å¤ÏCube ¤Î¥¤¥ó¥¹¥Ú¥¯¥¿¡¼¤ò³Îǧ¤·¡¢¤Á¤ã¤ó¤ÈColliderTest¥³¥ó¥Ý¡¼¥Í¥ó¥È¤¬Äɲ䵤ì¤Æ¤¤¤ë¤«¡¢³Îǧ¤·¤Þ¤¹¡£
¤â¤·¤â¥¢¥¿¥Ã¥Á¤Ç¤¤Ê¤¤¤è¤¦¤Ç¤¢¤ì¤Ð¡¢Console¤ò³Îǧ¤·¤Þ¤·¤ç¤¦¡£¥¨¥é¡¼¤¬½Ð¤Æ¤¤¤ë²ÄǽÀ¤¬¹â¤¤¤Ç¤¹¡£
¡¡Ìµ»ö¤Ë¥¢¥¿¥Ã¥Á¤¬¤Ç¤¤¿¤é¡¢¥²¡¼¥à¤ò¼Â¹Ô¤·¡¢ÀßÄꤷ¤¿¥Ü¥¿¥ó¤ò²¡¤·¤Æ¤ß¤Þ¤·¤ç¤¦¡£
¥Ò¥¨¥é¥ë¥¡¼¤Ë¤¢¤ë Cube ¥²¡¼¥à¥ª¥Ö¥¸¥§¥¯¥È¤òÁªÂò¤·¤Æ¤ª¤¯¤³¤È¤Ç¡¢¥¤¥ó¥¹¥Ú¥¯¥¿¡¼¾å¤«¤é¡¢BoxCollider ¥³¥ó¥Ý¡¼¥Í¥ó¥È¤Î¥ª¥ó¥ª¥Õ¤ÎÀ©¸æÀÚ¤êÂؤ¨¤¬³Îǧ¤¬¤Ç¤¤ë¤È»×¤¤¤Þ¤¹¡£
¡¡BoxCollider ¥³¥ó¥Ý¡¼¥Í¥ó¥È¤Îº¸Â¦¤Ë¤¢¤ë¥Á¥§¥Ã¥¯¥Ü¥Ã¥¯¥¹¤Î¥Á¥§¥Ã¥¯¤¬¡¢Æþ¤Ã¤¿¤ê³°¤ì¤¿¤ê¤¹¤ì¤ÐÀ©¸æÀ®¸ù¤Ç¤¹¡£
¡¡¥¹¥¯¥ê¥×¥È¤ò½¤Àµ¤·¡¢¥ª¥ó¥ª¥Õ¤ÎÀÚ¤êÂؤ¨Éôʬ¤ò¡¢¤è¤ê¥¹¥Þ¡¼¥È¤Ëµ½Ò¤¹¤ëÊýË¡¤ò³Ø½¬¤·¤Þ¤·¤ç¤¦¡£
¡¡bool ·¿¤ÎÊÑ¿ô¤Ë¸Â¤ê¡¢! ±é»»»Ò¤òÍøÍѤ¹¤ë¤³¤È¤Ç¡¢¸½ºß¤Î¾õÂÖ¤òȿž¤µ¤»¤ë½èÍý¤òµ½Ò¤Ç¤¤Þ¤¹¡£
¤³¤Îµ¡Ç½¤ò³èÍѤ¹¤ë¤È¡¢true => false ¤È¤Ê¤ê¡¢false => true ¤Èȿž¤µ¤»¤ë¤³¤È¤¬½ÐÍè¤Þ¤¹¡£
using System.Collections; using System.Collections.Generic; using UnityEngine; /// <summary> /// ¥³¥é¥¤¥À¡¼¤Î¥Æ¥¹¥ÈÍÑ¥¯¥é¥¹ /// ¥³¥ó¥Ý¡¼¥Í¥ó¥È¤Î¼èÆÀ¤È¥ª¥ó¡¿¥ª¥Õ¡¢¥³¥ó¥Ý¡¼¥Í¥ó¥È¤Î»ý¤Ä¥×¥í¥Ñ¥Æ¥£¤ÎÊѹ¹¤ò¹Ô¤¦ /// </summary> public class ColliderTest : MonoBehaviour { [Header("¥³¥é¥¤¥À¡¼¡ÊÀÜ¿¨È½Äê¡Ë¤Î¥ª¥ó¥ª¥ÕÍÑ")] public BoxCollider boxCollider; void Start() { } void Update() { // ¥Ü¥¿¥ó¤ò²¡¤¹ÅÙ¤ËBoxCollider¥³¥ó¥Ý¡¼¥Í¥ó¥È¤Î¾õÂÖ¤ò¥ª¥ó¡¦¥ª¥ÕÀÚ¤êÂؤ¨¤ë if (Input.GetKeyDown(KeyCode.A)) { // [ÊÑ¿ô̾.enabled]¤Ç¸½ºß¤Î¥³¥ó¥Ý¡¼¥Í¥ó¥È¤Î¾õÂÖ¤ò³Îǧ¤Ç¤¤ë¡£true¤Ê¤é¥ª¥ó¤Î¾õÂÖ //if (boxCollider.enabled == true) { // ¥ª¥Õ¤ËÀÚ¤êÂؤ¨¤ë //boxCollider.enabled = false; //} else { // if¤Î¾ò·ï¤Ç¤Ê¤¤¤Ê¤é¡¢¤³¤Á¤é¤Î½èÍý¤ò¼Â¹Ô = false¤Î¾ì¹ç //boxCollider.enabled = true; //} // 1¹Ô¤Ç½ñ¤¯¾ì¹ç(¾åµ¤ÎÆâÍƤÈƱ¤¸½èÍý¤Ë¤Ê¤ë) boxCollider.enabled = !boxCollider.enabled; } } }
¡¡½¾Íè¤Î½èÍý¤Ï¥³¥á¥ó¥È¥¢¥¦¥È¤·¡¢¿·¤·¤¤½èÍý¤ò1¹ÔÄɲ䷤Ƥ¯¤À¤µ¤¤¡£
¡¡¥¹¥¯¥ê¥×¥È¤ò½¤Àµ¤·¤¿¤é¥»¡¼¥Ö¤ò¤·¤Þ¤¹¡£
¡¡¥²¡¼¥à¤ò¼Â¹Ô¤·¤Æ¡¢¤¤¤Þ¤Þ¤Ç¤ÈƱ¤¸¤è¤¦¤ËÀ©¸æ¤¬¹Ô¤¨¤ë¤«¤ò³Îǧ¤·¤Æ¤¯¤À¤µ¤¤¡£
¡¡¥¹¥¯¥ê¥×¥È¤ò½¤Àµ¤·¡¢º£Å٤ϡ¢IsTrigger ¥×¥í¥Ñ¥Æ¥£¤Ë¤Ä¤¤¤Æ¡¢¥Ü¥¿¥ó¤ò²¡¤¹¤¿¤Ó¤Ë¥ª¥ó¥ª¥Õ¤¬ÀÚ¤êÂؤï¤ëµ¡Ç½¤ò¼ÂÁõ¤·¤Æ¤ß¤Þ¤·¤ç¤¦¡£
using System.Collections; using System.Collections.Generic; using UnityEngine; /// <summary> /// ¥³¥é¥¤¥À¡¼¤Î¥Æ¥¹¥ÈÍÑ¥¯¥é¥¹ /// ¥³¥ó¥Ý¡¼¥Í¥ó¥È¤Î¼èÆÀ¤È¥ª¥ó¡¿¥ª¥Õ¡¢¥³¥ó¥Ý¡¼¥Í¥ó¥È¤Î»ý¤Ä¥×¥í¥Ñ¥Æ¥£¤ÎÊѹ¹¤ò¹Ô¤¦ /// </summary> public class ColliderTest : MonoBehaviour { [Header("¥³¥é¥¤¥À¡¼¡ÊÀÜ¿¨È½Äê¡Ë¤Î¥ª¥ó¥ª¥ÕÍÑ")] public BoxCollider boxCollider; void Start() { } void Update() { // ¥Ü¥¿¥ó¤ò²¡¤¹ÅÙ¤ËBoxCollider¥³¥ó¥Ý¡¼¥Í¥ó¥È¤Î¾õÂÖ¤ò¥ª¥ó¡¦¥ª¥ÕÀÚ¤êÂؤ¨¤ë if (Input.GetKeyDown(KeyCode.A)) { //¥ª¥ó¥ª¥Õ¤ËÀÚ¤êÂؤ¨¤ë boxCollider.enabled = !boxCollider.enabled; } ////*¡¡¤³¤³¤«¤é½èÍý¤òÄɲä·¤Þ¤¹ *///// // ¥Ü¥¿¥ó¤ò²¡¤¹ÅÙ¤ËBoxCollider¥³¥ó¥Ý¡¼¥Í¥ó¥È¤Î»ý¤ÄIsTrigger¥×¥í¥Ñ¥Æ¥£¤Î¥ª¥ó¡¦¥ª¥Õ¤òÀÚ¤êÂؤ¨¤ë if (Input.GetKeyDown(KeyCode.S)) { if (!boxCollider.isTrigger) { // boxCollider.isTrigger == false¤ÈƱ¤¸ // ¥ª¥Õ¤Ê¤é¥ª¥ó¤Ë¤¹¤ë boxCollider.isTrigger = true; } else { // ¥ª¥ó¤Ê¤é¥ª¥Õ¤Ë¤¹¤ë // if-elseʸ¤Ê¤Î¤Ç¡¢É¬¤º¤É¤Á¤é¤«¤Îʬ´ô¤ËÆþ¤ë boxCollider.isTrigger = false; } } ////*¡¡¤³¤³¤Þ¤Ç *///// } }
¡¡¥Ò¥¨¥é¥ë¥¡¼¤Ë¤¢¤ë Cube ¥²¡¼¥à¥ª¥Ö¥¸¥§¥¯¥È¤òÁªÂò¤·¤Æ¡¢¥²¡¼¥à¤ò¼Â¹Ô¤·¤Þ¤¹¡£
»ØÄꤵ¤ì¤¿¥Ü¥¿¥ó¤ò²¡¤¹¤¿¤Ó¤Ë¡¢BoxCollider ¥³¥ó¥Ý¡¼¥Í¥ó¥ÈÆâ¤Ë¤¢¤ë IsTrigger ¥×¥í¥Ñ¥Æ¥£¤Î¥Á¥§¥Ã¥¯¤¬³°¤ì¤¿¤ê¡¢Æþ¤Ã¤¿¤ê¤¹¤ì¤ÐÀ©¸æÀ®¸ù¤Ç¤¹¡£
¡¡¥¹¥¯¥ê¥×¥È¤ò½¤Àµ¤·¡¢º£Å٤ϡ¢IsTrigger ¥×¥í¥Ñ¥Æ¥£¤Ë¤Ä¤¤¤Æ¡¢¥Ü¥¿¥ó¤ò²¡¤¹¤¿¤Ó¤Ë¥ª¥ó¥ª¥Õ¤¬ÀÚ¤êÂؤï¤ëµ¡Ç½¤ò¼ÂÁõ¤·¤Æ¤ß¤Þ¤·¤ç¤¦¡£
using System.Collections; using System.Collections.Generic; using UnityEngine; /// <summary> /// ¥³¥é¥¤¥À¡¼¤Î¥Æ¥¹¥ÈÍÑ¥¯¥é¥¹ /// ¥³¥ó¥Ý¡¼¥Í¥ó¥È¤Î¼èÆÀ¤È¥ª¥ó¡¿¥ª¥Õ¡¢¥³¥ó¥Ý¡¼¥Í¥ó¥È¤Î»ý¤Ä¥×¥í¥Ñ¥Æ¥£¤ÎÊѹ¹¤ò¹Ô¤¦ /// </summary> public class ColliderTest : MonoBehaviour { [Header("¥³¥é¥¤¥À¡¼¡ÊÀÜ¿¨È½Äê¡Ë¤Î¥ª¥ó¥ª¥ÕÍÑ")] public BoxCollider boxCollider; void Start() { } void Update() { // ¥Ü¥¿¥ó¤ò²¡¤¹ÅÙ¤ËBoxCollider¥³¥ó¥Ý¡¼¥Í¥ó¥È¤Î¾õÂÖ¤ò¥ª¥ó¡¦¥ª¥ÕÀÚ¤êÂؤ¨¤ë if (Input.GetKeyDown(KeyCode.A)) { //¥ª¥ó¥ª¥Õ¤ËÀÚ¤êÂؤ¨¤ë boxCollider.enabled = !boxCollider.enabled; } // ¥Ü¥¿¥ó¤ò²¡¤¹ÅÙ¤ËBoxCollider¥³¥ó¥Ý¡¼¥Í¥ó¥È¤Î»ý¤ÄIsTrigger¥×¥í¥Ñ¥Æ¥£¤Î¥ª¥ó¡¦¥ª¥Õ¤òÀÚ¤êÂؤ¨¤ë if (Input.GetKeyDown(KeyCode.S)) { //if (!boxCollider.isTrigger) { // boxCollider.isTrigger == false¤ÈƱ¤¸ // ¥ª¥Õ¤Ê¤é¥ª¥ó¤Ë¤¹¤ë //boxCollider.isTrigger = true; //} else { // ¥ª¥ó¤Ê¤é¥ª¥Õ¤Ë¤¹¤ë // if-elseʸ¤Ê¤Î¤Ç¡¢É¬¤º¤É¤Á¤é¤«¤Îʬ´ô¤ËÆþ¤ë //boxCollider.isTrigger = false; //} ¡¡¡¡¡¡¡¡¡¡¡¡boxCollider.isTrigger = !boxCollider.isTrigger; } } }
¡¡Àè¤Û¤É¤ÈƱ¤¸¤è¤¦¤Ë if / else ʸ¤ÎÉôʬ¤ò¥³¥á¥ó¥È¥¢¥¦¥È¤·¡¢¿·¤·¤¤½èÍý¤òÄɲä·¤Þ¤¹¡£
¡¡isTrigger ¥×¥í¥Ñ¥Æ¥£¤â bool ·¿¤Ç¤¢¤ë¤¿¤á¡¢¤³¤Î¤è¤¦¤Ë½ñ¤´¹¤¨¤ë¤³¤È¤¬½ÐÍè¤Þ¤¹¡£
- ¥«¥Æ¥´¥ê¡§
- ¿Ê³Ø/¥¹¥¯¡¼¥ë
- Áí¹ç
¥³¥á¥ó¥È¤ò¤«¤¯