ºÇ½ª¹¹¿·¡§ orika_ex_miyako 2024ǯ01·î05Æü(¶â) 13:59:09ÍúÎò
¡¡¥¢¥¤¥Æ¥à¤Ë¿¨¤ì¤¿¤é¼«Æ°Åª¤Ë¥¢¥¤¥Æ¥à¤ò¼èÆÀ¤¹¤ë¥¿¥¤¥×¤Î¼ÂÁõÊýË¡¤Ç¤Ï¤¢¤ê¤Þ¤»¤ó¡£
¡¡ÆÃÄê¤Î¥Ü¥¿¥ó¤ò²¡¤·¤¿ºÝ¤Ë¡¢¥³¥é¥¤¥À¡¼¤ò»ý¤Ä¸«¤¨¤Ê¤¤¥²¡¼¥à¥ª¥Ö¥¸¥§¥¯¥È¤ò¥×¥ì¥¤¥ä¡¼¤Î¼þ°Ï¤ËŸ³«¤·¡¢
¤½¤Î¥³¥é¥¤¥À¡¼¤ÎÈÏ°ÏÆâ¤Ë¤¢¤ë¥²¡¼¥à¥ª¥Ö¥¸¥§¥¯¥È¤òÀººº¤·¤Æ¡¢¥¢¥¤¥Æ¥à¤Ç¤¢¤Ã¤¿¾ì¹ç¤Ë¤Ï¼èÆÀ¤¹¤ë¤È¤¤¤¦µ¡Ç½¤Ç¤¹¡£
¡¡¶ñÂÎŪ¤Ê¥¢¥¤¥Æ¥à¤Î¸ú²Ì¤Ê¤É¤Ï´Þ¤ß¤Þ¤»¤ó¤Î¤Ç¡¢¤½¤ÎÉôʬ¤Ë¤Ä¤¤¤Æ¤ÏÊÌÅÓ¡¢¼ÂÁõ¤ò¤ª¤³¤Ê¤Ã¤Æ¤¯¤À¤µ¤¤¡£
¡¡¥¢¥¤¥Æ¥à¤ÎȽÄêÊýË¡¤Ë¤Ä¤¤¤Æ¡¢¤³¤³¤Ç¤ÏÊ£¿ô¤Î¥¢¥×¥í¡¼¥Á¤òÄ󼨤·¤Þ¤¹¡£
¼èÆÀ»þ¤Îµ¡Ç½(¥³¥é¥¤¥À¡¼¤ÎŸ³«Éôʬ)¤Ï¡¢¤¹¤Ù¤ÆƱ¤¸µ¡Ç½¤òÍøÍѤ·¤Æ¤¤¤Þ¤¹¡£
¡¡¤Ê¤ªµ»ö¼«ÂΤϣ³£ÄÍѤǤ¹¤¬¡¢£²£Ä¤Ç¤â±þÍѲÄǽ¤Ç¤¹¡£
¡¡¤â¤Ã¤È¤â°ìÈÌŪ¤Ç¡¢¼ÂÁõ¤¬ÍưפÊÊýË¡¤Ç¤¹¡£
¡¡»öÁ°¤Ë¥¿¥°¤òºîÀ®¤·¡¢¸¡½Ð¤µ¤ì¤ë¦(¥¢¥¤¥Æ¥à¦)¤Ë¥¿¥°¤òÀßÄꤷ¤Æ¤ª¤¯É¬Íפ¬¤¢¤ê¤Þ¤¹¡£
¤Þ¤¿¡¢¥¿¥°¤Ë¤è¤ëȽÄê¤Ïʸ»úÎó¤Ç¤¢¤ë¤¿¤á¡¢Âçʸ»ú¾®Ê¸»ú¤Î¶èÊ̤¬¤¢¤ê¤Þ¤¹¤Î¤Ç¡¢´Ö°ã¤¨¤Ê¤¤¤è¤¦¤ËºîÀ®¤·¤Æ¤¯¤À¤µ¤¤¡£
¡¡¹½Ê¸Æâ¤Ç¤Ï¡¢if ʸ¤Ë¤è¤ë¥Í¥¹¥È(Æþ¤ì»Ò¹½Â¤)¤ò¿¼¤¯¤Ê¤é¤Ê¤¤¤è¤¦¤Ë¡¢continue ¤ò¤·¤Æ¤¤¤Þ¤¹¡£
¡¡¾ò·ï¤¬À®Î©¤·¤¿¤é¡¢¤È¤¤¤¦·Á¤Ç½èÍý¤òºî¤ë¤À¤±¤Ç¤Ï¤Ê¤¯¡¢¾ò·ï¤¬À®Î©¤·¤Ê¤«¤Ã¤¿¤é¡¢¤È¤¤¤¦·Á¤Ç½èÍý¤òºî¤ë¤³¤È¤¬½ÐÍè¤Þ¤¹¡£
¡¡Unity ¤Î Physics ¥¯¥é¥¹¤ËÍÑ°Õ¤µ¤ì¤Æ¤¤¤ë¥á¥½¥Ã¥É¤Î£±¤Ä¤Ç¤¹¡£µåÂηÁ¤Î¥³¥é¥¤¥À¡¼¤ò°ì»þŪ¤ËÀ¸À®¤·¡¢Â¾¤Î¥³¥é¥¤¥À¡¼¤È¤Î¿¯ÆþȽÄê¤ò¹Ô¤¦¤³¤È¤¬¤Ç¤¤Þ¤¹¡£
ȽÄê·ë²Ì¤È¤·¤Æ¡¢Collider ÇÛÎ󷿤ÎÌá¤êÃͤò»ý¤Á¤Þ¤¹¡£
¡¡Â¾¤Ë¤â .OverlapBox ¥á¥½¥Ã¥É¡¢OverlapCapsule ¥á¥½¥Ã¥É¤¬¤¢¤ê¡¢¤½¤ì¤¾¤ì¤Ë·Á¾õ¤¬°ã¤¤¤Þ¤¹¡£Ìá¤êÃͤϤ¤¤º¤ì¤â Collider ÇÛÎ󷿤ÇƱ¤¸¤Ç¤¹¡£
// ¥¥ã¥é¥¯¥¿¡¼¤òÃæ¿´¤Ë¡¢radius ¤òȾ·Â¤È¤·¤¿±ß·Á¤Î¥³¥é¥¤¥À¡¼¤òºîÀ®¤·¡¢¤½¤ÎÈÏ°ÏÆâ¤Ë¤¢¤ë¤¹¤Ù¤Æ¤Î¥³¥é¥¤¥À¡¼¤ò¸¡½Ð¤·¤ÆÇÛÎó¤Ë¤¹¤ë Collider[] hitColliders = Physics.OverlapSphere(transform.position, radius);
¡¡OverlapSphere ¥á¥½¥Ã¥É¤ò¼Â¹Ô¤¹¤ë¤È¡¢Âè1°ú¿ô¤Î°ÌÃÖ¤ò»ÏÅÀ¤Ë¡¢Âè2°ú¿ô¤ÎÃͤòȾ·Â¤È¤·¤¿±ß·Á¤Î¥³¥é¥¤¥À¡¼¤òŸ³«¤·¤Þ¤¹¡£
¤³¤Î¤È¤¡¢¤³¤Î¥³¥é¥¤¥À¡¼¤ÎÈÏ°ÏÆâ¤Ë¤¢¤ë¡¢Ê̤Υ²¡¼¥à¥ª¥Ö¥¸¥§¥¯¥È¤Î¥³¥é¥¤¥À¡¼¤ò¸¡½Ð¤·¡¢¤½¤ì¤é¤ò¤Þ¤È¤á¤ÆÇÛÎó¤ËÆþ¤ì¤ÆÌá¤êÃͤȤ·¤ÆÄ󶡤·¤Þ¤¹¡£
¡¡¤½¤Î¤¿¤áº£²ó¤Î¤è¤¦¤Ë¡¢¥³¥é¥¤¥À¡¼ÇÛÎ󷿤ÎÊÑ¿ô¤òÍÑ°Õ¤·¤Æ¤ª¤¯¤³¤È¤ÇÂåÆþ¤·¡¢°Ê¹ß¤Î½èÍý¤ÇÍøÍѤ·¤Æ¤¤¤¯¤³¤È¤¬½ÐÍè¤Þ¤¹¡£
¡¡¤³¤Î¥á¥½¥Ã¥É¤Ë¤Ï OverlapSphereNonAlloc ¥á¥½¥Ã¥É¤âÍÑ°Õ¤µ¤ì¤Æ¤ª¤ê¡¢¤³¤Á¤é¤ÎÊý¤¬¥¬¥Ù¡¼¥¸¤òÀ¸À®¤·¤Ê¤¤Ê¬Í¥¤ì¤Æ¤¤¤Þ¤¹¤¬¡¢»öÁ°¤ËÇÛÎó¤ÎŤµ¤ò»ØÄꤷ¤Ê¤±¤ì¤Ð¤Ê¤ê¤Þ¤»¤ó¡£
ÍøÍÑÊýË¡¤òÍý²ò¤Ç¤¤Æ¤¤¿¤é¡¢¥ê¥Õ¥¡¥¯¥¿¥ê¥ó¥°¤·¤Æ½èÍý¤ÎÃÖ¤´¹¤¨¤Ë¥Á¥ã¥ì¥ó¥¸¤·¤Æ¤ß¤ë¤È¤è¤¤¤Ç¤·¤ç¤¦¡£
»²¹Í¥µ¥¤¥È
Unity ¸ø¼°¥¹¥¯¥ê¥×¥È¡¦¥ê¥Õ¥¡¥ì¥ó¥¹
Physics.OverlapSphere
Unity ¸ø¼°¥¹¥¯¥ê¥×¥È¡¦¥ê¥Õ¥¡¥ì¥ó¥¹
Physics.OverlapSphereNonAlloc
¡¡£²£ÄÍѤâÍÑ°Õ¤µ¤ì¤Æ¤Þ¤¹¡£
¥á¥½¥Ã¥É̾¤Ï OverlapSphere ¤Ç¤Ï¤Ê¤¯¡¢OverlapCircle ¥á¥½¥Ã¥É¤È OverlapCircleNonAlloc ¥á¥½¥Ã¥É¤Ç¤¹¡£
»²¹Í¥µ¥¤¥È
Unity ¸ø¼°¥¹¥¯¥ê¥×¥È¡¦¥ê¥Õ¥¡¥ì¥ó¥¹
Physics2D.OverlapCircle
Unity ¸ø¼°¥¹¥¯¥ê¥×¥È¡¦¥ê¥Õ¥¡¥ì¥ó¥¹
Physics2D.OverlapCircleNonAlloc
¡¡Àè¤Û¤ÉÍøÍѤ·¤Æ¤¤¤ë Physics.OverlapSphere ¥á¥½¥Ã¥É¤Î°ú¿ô¤Ë¤ÏÂè3°ú¿ô¤ÈÂè4°ú¿ô¤¬¤¢¤ê¡¢¤³¤Á¤é¤Ë¤Ï½é´üÃͤ¬ÂåÆþ¤µ¤ì¤Æ¤¤¤Þ¤¹¡£
¤½¤Î¤¿¤á¡¢Âè2°ú¿ô¤Þ¤Ç»ØÄꤹ¤ì¤ÐÍøÍѤǤ¤ë¤è¤¦¤Ë¤Ê¤Ã¤Æ¤¤¤Þ¤¹¡£
¡¡Âè3°ú¿ô¤Ë¤Ï¥ì¥¤¥ä¡¼¤Î»ØÄ꤬¤Ç¤¤ë¤¿¤á¡¢¤½¤Î¾ì¹ç¡¢Physics.OverlapSphere ¥á¥½¥Ã¥É¤ò¼Â¹Ô¤¹¤ë¤È¡¢¥á¥½¥Ã¥É¤ÎÈÏ°ÏÆâ¤Ë¤¢¤ë¡¢»ØÄꤷ¤¿¥ì¥¤¥ä¡¼¤Î¤ß¤òÇÛÎó¤È¤·¤Æ¼èÆÀ½ÐÍè¤Þ¤¹¡£
¤½¤Î¤¿¤á¡¢if ʸ¤Ë¤è¤ëȽÄê¤ò¾Êά¤Ç¤¤Þ¤¹¡£
¡¡»öÁ°¤Ë¥ì¥¤¥ä¡¼¤òºîÀ®¤·¡¢¥¤¥ó¥¹¥Ú¥¯¥¿¡¼¤Ç¸¡½Ð¤·¤¿¤¤¥ì¥¤¥ä¡¼¤ò»ØÄꤷ¤Þ¤¹¡£
¤Þ¤¿¡¢¸¡½Ð¤µ¤ì¤ë¦(¥¢¥¤¥Æ¥à¦)¤Ë¥ì¥¤¥ä¡¼¤òÀßÄꤷ¤Æ¤ª¤¯É¬Íפ¬¤¢¤ê¤Þ¤¹¡£
¡¡ÍøÅÀ¤È¤·¤Æ¤Ï¡¢Physics.OverlapSphere ¥á¥½¥Ã¥É¤Ç¸¡½Ð¤µ¤ì¤ë¥³¥é¥¤¥À¡¼¤ò¤Õ¤ë¤¤¤Ë¤«¤±¤Æ¡¢»ØÄꤷ¤¿¥ì¥¤¥ä¡¼¤Î¾ðÊó¤Î¤ß¤ÇÌá¤êÃͤòºîÀ®¤Ç¤¤ë¤³¤È¤Ç¤¹¡£
¤½¤Î¤¿¤á¡¢ÇÛÎó¤ÎÃæ¿È¤Ï¤¹¤Ù¤Æ»ØÄꤷ¤¿¥ì¥¤¥ä¡¼¤Î¥³¥é¥¤¥À¡¼¤Î¤ß¤Ç¤¢¤ë¤³¤È¤¬Êݾڤµ¤ì¤ë¤¿¤á¡¢¥¿¥°¤È¤Ï°Û¤Ê¤ê¡¢if ʸ¤Ë¤è¤ëȽÄ꤬ÉÔÍפˤʤäƤ¤¤Þ¤¹¡£
¡¡Á°½Ò¤Î¥ì¥¤¥ä¡¼¤ò¥Ù¡¼¥¹¤Ë¡¢½èÍý¤Î¼ÂÍÑŪ¤Ë¤·¤Æ¸úΨ²½¤ò¤ª¤³¤Ê¤Ã¤¿¹½Ê¸¤Ç¤¹¡£
¡¡¥¢¥¤¥Æ¥à½èÍý¤ÎÃê¾Ý²½¤ò¥Ù¡¼¥¹¤Ë¡¢ItemBase ¥¯¥é¥¹¤ò¼èÆÀ¤Ç¤¤ë¤«¤ò³Îǧ¤·¤Æ¤¤¤Þ¤¹¡£
¥¿¥°¤ä¥ì¥¤¥ä¡¼¤Ç¤ÎȽÄê¤Î¾ì¹ç¡¢¥¢¥¤¥Æ¥à¤Î¸ú²Ì¤òÍøÍѤ¹¤ë¥¿¥¤¥ß¥ó¥°¤ÇÊÌÅÓ¡¢¥¢¥¤¥Æ¥à¤Î¥¯¥é¥¹¤Î¼èÆÀ(GetComponent ¥á¥½¥Ã¥É)¤¬É¬Íפˤʤê¤Þ¤¹¤¬
¤³¤Á¤é¤Î¥¢¥×¥í¡¼¥Á¤Ç¤¢¤ì¤Ð¤¹¤Ç¤Ë¥¯¥é¥¹¤ò¼èÆÀ¤·¤Æ¤¤¤ë¤Î¤Ç GetComponent ¥á¥½¥Ã¥É¤¬ÉÔÍפǤ¹¡£(¤¹¤°¤ËÌ¿Î᤬½Ð¤»¤Þ¤¹¡£)
¡¡¤Ç¤¤ë¸Â¤ê¡¢¥¿¥°¤ä¥ì¥¤¥ä¡¼¤Ç¤ÎȽÄê¤Ç¤Ï¤Ê¤¯¡¢¥¯¥é¥¹¤Ç¤ÎȽÄê¤ò¹Ô¤¦¤è¤¦¤Ë¤·¤Þ¤¹¡£
¤½¤·¤Æ¥ì¥¤¥ä¡¼¤Ë¤Ä¤¤¤Æ¤Ï¡¢³èÍѤǤ¤ëÉôʬ¤Ç¤Ï¾å¼ê¤¯ÁȤ߹ç¤ï¤»¤Æ¤¤¤¤Þ¤·¤ç¤¦¡£
¡¡UniRx ¤Îµ¡Ç½¤òÍøÍѤ·¤Æ¡¢¥Ü¥¿¥ó¤ÎȽÄê¤ò¥¤¥Ù¥ó¥È¶îÆ°·¿¤Ë¥ê¥Õ¥¡¥¯¥¿¥ê¥ó¥°¤·¤¿¤â¤Î¤Ç¤¹¡£
¥¢¥¤¥Æ¥à¤ÎȽÄêÊýË¡¤Ï¡Ú£³¡¥¥¯¥é¥¹¤Ë¤è¤ëȽÄêÊýË¡¡Û¤òºÎÍѤ·¤Æ¤¤¤Þ¤¹¡£
¡¡Update ¥á¥½¥Ã¥ÉÆâ¤Ç½èÍý¤·¤Æ¤¤¤¿¥Ü¥¿¥ó¤Î²¡²¼³Îǧ½èÍý¤ò Start ¥á¥½¥Ã¥ÉÆâ¤Ç¤Î¥Ü¥¿¥ó¤Î¹ØÆɽèÍý¤Ë¥ê¥Õ¥¡¥¯¥¿¥ê¥ó¥°¤·¤Æ¤¤¤Þ¤¹¡£
- ¥«¥Æ¥´¥ê¡§
- ¿Ê³Ø/¥¹¥¯¡¼¥ë
- ¥×¥í¥°¥é¥ß¥ó¥°
¥³¥á¥ó¥È¤ò¤«¤¯