ºÇ½ª¹¹¿·¡§ orika_ex_miyako 2024ǯ04·î02Æü(²Ð) 17:35:00ÍúÎò
£²¥Ñ¥¿¡¼¥ó¤Î¼ÂÁõÎã¤ò£²¤Ä¤Î¼ê½ç¤Ëʬ¤±¤Æ²òÀ⤷¤Þ¤¹¡£
¡¡¤³¤Î¼ê½ç¤Ë¤ª¤¤¤Æ¤Ï¡¢¥²¡¼¥àÆâ¤Ç¾ã³²Êª¤¬Æ°Åª¤ËÀ¸À®¤µ¤ì¤¿¥¿¥¤¥ß¥ó¥°¤Ç¤ÎºÆ Bake ¤Ç¤Ï¤Ê¤¯¡¢
¾ã³²Êª¤È¥¨¡¼¥¸¥§¥ó¥È¤¬ÀÜ¿¨¤·¤¿¥¿¥¤¥ß¥ó¥°¤ÇºÆ Bake ¤ò¹Ô¤¤¡¢·ÐÏ©¤¬ÊѲ½¤¹¤ë¥±¡¼¥¹¤Î¼ÂÁõÎã¤Ç¤¹¡£
¡¡¾åµ¤ÎÆ°²è¤Î¤è¤¦¤Ë¡¢¾ã³²Êª¤È¥¨¡¼¥¸¥§¥ó¥È¤¬ÀÜ¿¨¤·¤¿¥¿¥¤¥ß¥ó¥°¤Ç¿·¤·¤¤·ÐÏ©¤ÎºÆ·×»»¤ò¹Ô¤¤¡¢ÌÜŪÃϤòÌܻؤ¹µ¡Ç½¤Ç¤¹¡£
¡¡NavMeshComponents ¤Ï£²£Ä¤Ç¤Î NavMesh µ¡Ç½¤Î³èÍѤΤۤ«¡¢¥²¡¼¥àÆâ¤Ç¤ÎưŪ¤Ê Bake ¤ò¼«Æ°Åª¤Ë¹Ô¤¦µ¡Ç½¤¬¤Ä¤¤¤Æ¤¤¤Þ¤¹¡£
¤³¤ì¤Ï¥¤¥ó¥¹¥Ú¥¯¥¿¡¼¤«¤éÀßÄê²Äǽ¤Ç¤¹¡£
¡¡¤³¤Á¤é¤Îµ¡Ç½¤òÍøÍѤ¹¤ë¤È¡¢Î㤨¤Ð¾ã³²ÊªÍѤΥª¥Ö¥¸¥§¥¯¥È¤¬À¸À®¤µ¤ì¤¿¤ê¡¢°ÜÆ°¤·¤¿¤ê¤¹¤ë¤È¡¢
¨ºÂ¤Ë Bake ¤Î¥ê¥Ó¥ë¥É(¥ê¥Ù¥¤¥¯)¤¬Áö¤ê¡¢Bake ÈϰϤò¹¹¿·¤¹¤ë¤³¤È¤¬²Äǽ¤Ë¤Ê¤ê¤Þ¤¹¡£
¤è¤Ã¤Æ¡¢¤½¤Î¿·¤·¤¤ Bake ¤µ¤ì¤¿ÈϰϤòÍøÍѤ·¤Æ¡¢¿·¤·¤¤·ÐÏ©·×»»¤¬¹Ô¤ï¤ì¤ë¤è¤¦¤Ë¤Ê¤ê¤Þ¤¹¡£
¡¡¤¿¤À¤·¡¢¤³¤Îµ¡Ç½¤òÍøÍѤ·¤¿¾ì¹ç¡¢¥¨¡¼¥¸¥§¥ó¥È¤Ï¾ã³²Êª¤ËÀÜ¿¨¤·¤Ê¤¯¤Æ¤â·ÐÏ©Êѹ¹¤¬È¯À¸¤·¤Þ¤¹¡£
¤½¤Î¤è¤¦¤Ê¾õ¶·¤¬¹¥¤Þ¤·¤¯¤Ê¤¤ = ¤¤¤º¤ì¤«¤Î¥¨¡¼¥¸¥§¥ó¥È¤¬¾ã³²Êª¤ËÀÜ¿¨¤·¤Æ½é¤á¤Æ·ÐÏ©Êѹ¹¤¬Æþ¤ë¤è¤¦¤Ë¤·¤¿¤¤¡¢¤È¤¤¤¦¥±¡¼¥¹¤òÁÛÄꤷ¤¿¼ÂÁõÎã¤Ë¤Ê¤ê¤Þ¤¹¡£
¡¡»öÁ°¤Î½àÈ÷¤È¤·¤Æ¤Ï¡¢¡Ú£²£Ä¡ÛNavMeshComponents ¤òÍøÍѤ·¤¿·ÐÏ©°ÜÆ°½èÍý¤Î¼ÂÁõÎ㡤γؽ¬¤È¼ÂÁõ¤¬½ªÎ»¤·¤Æ¤¤¤ë¤³¤È¤òÁ°Äó¤È¤·¤Æ¤¤¤Þ¤¹¡£
¡¡²¼µ¤Î»²¹Í²èÁü¤Î¤è¤¦¤Ë¡¢¥¿¥¤¥ë¥Þ¥Ã¥×¾å¤Ë°ÜÆ°²Äǽ¤Ê¥ë¡¼¥È¤¬ Bake ¤µ¤ì¤Æ¤¤¤ë¤³¤È¤ò³Îǧ¤·¤Æ¤¯¤À¤µ¤¤¡£
¡¡²èÌ̱¦Ã¼¤Î¹õ¤¤Éôʬ¤¬ÌÜɸÃÏÅÀ¤Ç¤¹¡£
¡¡Update Method ¤ÎÀßÄê¤ò Manual ¤ËÀßÄꤷ¤Æ¤ª¤¯¤³¤È¤Ç¡¢
¥²¡¼¥à¼Â¹ÔÃæ¤Ë¤ª¤¤¤Æ¡¢¾ã³²Êª¤Ê¤É¤¬Äɲ䵤줿¤ê°ÜÆ°¤·¤¿¾ì¹ç¤Ç¤¢¤Ã¤Æ¤â¼«Æ°Åª¤Ë¤ÏºÆÅÙ Bake ¤¬¹Ô¤ï¤ì¤Ê¤¯¤Ê¤ê¤Þ¤¹¡£
¥¤¥ó¥¹¥Ú¥¯¥¿¡¼²èÁü
¡¡Update Async ¤Ë¥Á¥§¥Ã¥¯¤òÆþ¤ì¤Æ¤ª¤¯¤È¡¢ÆâÉô¤Ç AsyncOperation ¥¯¥é¥¹¤òÍøÍѤ·¤¿ÈóƱ´ü½èÍý¤Ë¤è¤ë Bake ¤¬¹Ô¤ï¤ì¤ë¤è¤¦¤Ë¤Ê¤ê¤Þ¤¹¡£
(¤¿¤À¤·¡¢AsyncOperation ¤¬ private ¤Ê¥á¥ó¥ÐÊÑ¿ô¤Ç¤¢¤ë¤¿¤á¡¢³°Éô¤«¤é¤Î³èÍѤ¬¤Ç¤¤ë¤è¤¦¤Ë¤Ï¤Ê¤Ã¤Æ¤¤¤Þ¤»¤ó¡£)
¡¡¤³¤Á¤é¤â´ðËÜŪ¤Ë¤Ï¥Á¥§¥Ã¥¯¤ÏÉÔÍפǤ¹¡£
¡¡Ç¤°Õ¤ËºîÀ®¤·¤Æ¤¯¤À¤µ¤¤¡£
¡¡²¼µ¤Ï¥µ¥ó¥×¥ë¤Ç¤¹¡£
¥µ¥ó¥×¥ë²èÁü
¥µ¥ó¥×¥ë²èÁü
¡¡NavMeshSourceTag2D ¥³¥ó¥Ý¡¼¥Í¥ó¥È¤ò¥¢¥¿¥Ã¥Á¤·¡¢Area ¤ò 1 ¤ËÀßÄꤷ¤Þ¤¹¡£
½é´üÀßÄê¤Ç¤Ï 1 ¤ËÀßÄꤹ¤ë¤³¤È¤Ç¡¢Bake »þ¤Ë·ÐÏ©Âоݤ«¤é½ü³°¤µ¤ì¤¿¥ª¥Ö¥¸¥§¥¯¥È(¾ã³²Êª°·¤¤)¤Ë¤Ê¤ê¤Þ¤¹¡£
¡¡³°Éô¤«¤é¤ÎÀÜ¿¨È½Äê¤ËÂбþ¤Ë¤¹¤ë¤¿¤á¡¢Tag ¤ò Wall ¤ËÀßÄꤷ¤¿¾å¡¢
¥ª¥Ö¥¸¥§¥¯¥È¤Î·Á¾õ¤Ë±þ¤¸¤¿£²£ÄÍÑ¥³¥é¥¤¥À¡¼¤È Rigidbody2D ¥³¥ó¥Ý¡¼¥Í¥ó¥È¤ò¥¢¥¿¥Ã¥Á¤·¤Æ¤¤¤Þ¤¹¡£
¡¡³°Éô¤«¤é¤ÎÀÜ¿¨¤Ç¾ã³²Êª¤¬°ÜÆ°¤·¤Ê¤¤¤è¤¦¤Ë¡¢Freeze Position ¤ä Freeze Rotation ¤Î¥Á¥§¥Ã¥¯¤òÆþ¤ì¤Æ¤ª¤¤¤Æ¤â¤è¤¤¤Ç¤·¤ç¤¦¡£
¡¡Å¬µ¹¡¢¼«Ê¬¤Î¥×¥í¥¸¥§¥¯¥È¤Ë¹ç¤ï¤»¤ÆºîÀ®¤·¤Æ¤¯¤À¤µ¤¤¡£
¡¡¥×¥ì¥Ï¥Ö¤Ë¤·¤Æ¤ª¤¯¤³¤È¤ÇưŪÀ¸À®¤ËÂбþ¤Ç¤¤Þ¤¹¡£
¤Þ¤¿ÀìÍѤΥ¯¥é¥¹¤ò¥¢¥¿¥Ã¥Á¤·¤Æ¤ª¤¯¤È¡¢¾ã³²Êª¤ÎµóÆ°(²èÁü¤Îº¹¤·Âؤ¨¡¢Âѵ×ÎÏÀßÄê¤Ê¤É)¤âÀ©¸æ¤Ç¤¤Þ¤¹¡£
¡¡ºîÀ®¤·¤¿¾ã³²ÊªÍѤΥª¥Ö¥¸¥§¥¯¥È¤ò Bake ¤µ¤ì¤Æ¤¤¤ë·ÐÏ©¤Î¾å¤ËÇÛÃÖ¤·¤Æ¤¯¤À¤µ¤¤¡£
NavMeshBuilder2D ¥³¥ó¥Ý¡¼¥Í¥ó¥È¤Î Bake On Enable ¤Ë¥Á¥§¥Ã¥¯¤¬Æþ¤Ã¤Æ¤¤¤Æ¤â
Update Method ¤ò Manual ¤ËÀßÄꤷ¤Æ¤¤¤ë¾ì¹ç¡¢¥¨¥Ç¥£¥¿¡¼¾å¤Ç¤â¡¢¥²¡¼¥à¼Â¹Ô»þ¤Ë¤ª¤¤¤Æ¤â¼«Æ°Åª¤Ë¤Ï Bake ¤¬¼Â¹Ô¤µ¤ì¤Ê¤¯¤Ê¤ê¤Þ¤¹¡£
¡¡¾ã³²Êª¤ò·ÐÏ©¤ËÈ¿±Ç¤·¤¿ÆâÍƤò³Îǧ¤·¤¿¤¤¾ì¹ç¤Ë¤Ï¡¢¼êÆ°¤Ç Bake ¥Ü¥¿¥ó¤ò²¡¤·¤Æ¤¯¤À¤µ¤¤¡£
¾ã³²Êª¤È¤·¤Æǧ¼±¤µ¤ì¤ë¤È Bake ÆâÍƤ¬¹¹¿·¤µ¤ì¤¿¤È¤¤Ë¾ã³²ÊªÃÏÅÀ¤Î·ÐÏ©¤¬¤Ê¤¯¤Ê¤ê¤Þ¤¹¡£
¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¢
¡¡NavMeshAgent ¤Îµ¡Ç½¤È¤·¤Æ¡¢ÌÜŪÃϤ¬ÊѤï¤é¤Ê¤±¤ì¤Ð¥ë¡¼¥È¤òºÆ·×»»¤·¤ÆÌÜŪÃϤòÌܻؤ·¤Þ¤¹¡£
¤½¤Î¤¿¤á¡¢¥²¡¼¥àÆâ¤ÇưŪ¤Ë Bake ¤¬¼Â¹Ô¤µ¤ì¤ì¤Ð¡¢¥¨¡¼¥¸¥§¥ó¥È¤ÎÌÜŪÃϤޤǤηÐÏ©¤Ï¥²¡¼¥àÆâ¤Ç¤â¼«Æ°Åª¤ËÊѤï¤ê¤Þ¤¹¡£
¡¡¥¿¥ï¡¼¥Ç¥£¥Õ¥§¥ó¥¹¤Î¶µºà¤ò¥Ù¡¼¥¹¤Ë¥µ¥ó¥×¥ë¥³¡¼¥É¤âÄ󼨤·¤Þ¤¹¡£
Á°Äó¤È¤·¤Þ¤·¤Æ¡¢¶µºà¤Î´ðÁÃÉôʬ¡Ê¥¿¥ï¡¼¥Ç¥£¥Õ¥§¥ó¥¹¤Î¼ê½ç£±¡Á£²£¸¤Þ¤Ç¡Ë¤ò¼ÂÁõºÑ¤Î¾õÂ֤ǤÎƳÆþ»öÎã¤Ë¤Ê¤ê¤Þ¤¹¡£
¡¡Å¨¤Î°ÜÆ°½èÍý¤ò DOTween ¤«¤é NavMeshAgent ¤ËÃÖ¤´¹¤¨¤¿¾ì¹ç¤Î¥µ¥ó¥×¥ë¥³¡¼¥É¤Ç¤¹¡£
¡¡NavMeshAgent ¤Îµ¡Ç½¤òÍøÍѤ¹¤ë¤¿¤á¡¢using ¤Ë UnityEngine.AI ¤òÄɲ䷤Ƥ¤¤Þ¤¹¡£
¡¡¿·¤·¤¤ SetUpEnemyController ¥á¥½¥Ã¥É¤òºîÀ®¤·¡¢°ú¿ô¤òÊѤ¨¤ë¥ª¡¼¥Ð¡¼¥í¡¼¥Éµ¡Ç½¤òºÎÍѤ·¤Æ¤¤¤Þ¤¹¡£
¤Þ¤¿Ìá¤êÃͤò»ý¤¿¤»¤Æ¤¤¤Þ¤¹¡£
¡¡¤½¤Î¤Û¤«¤Ë¤â NavMeshAgent ¤òÍøÍѤ¹¤ë¤¿¤á¤ÎÊÑ¿ô¤ä¥á¥½¥Ã¥É¤òÄɲ䷤Ƥ¤¤Þ¤¹¡£
EnemyController.cs
¡¡Å¨¤Î¥µ¥ó¥×¥ë¤Ç¤¹¡£
Åö¤¿¤êȽÄê¤ò¼è¤ë¤¿¤á Rigidbody2D ¤âÄɲ䵤ì¤Æ¤¤¤Þ¤¹¡£
¤Ê¤ª BodyType ¤ò Kinematic ¤Ë¤·¤Æ¤ª¤«¤Ê¤¤¤È NavMeshAgent ¤¬Àµ¤·¤¯Æ°¤¤Þ¤»¤ó¤Î¤ÇÃí°Õ¤·¤Æ¤¯¤À¤µ¤¤¡£
¡¡Å¨¤òÀ¸À®¤·¤¿¥¿¥¤¥ß¥ó¥°¤Ç¡¢Å¨¤Î°ÜÆ°ÌÜɸÃÏÅÀ¡¢NavMeshBuilder2D ¥³¥ó¥Ý¡¼¥Í¥ó¥È¤Î¾ðÊó¤ò°ú¿ô¤òÍøÍѤ·¤ÆÅϤ¹¤è¤¦¤Ë¤·¤Þ¤¹¡£
°ú¿ô¤òÅϤ¹¤¿¤á¤Ë EnemyController ¤Ë¿·¤·¤¯ SetUpEnemyController ¥á¥½¥Ã¥É¤òÄɲ䷤Ƥ¤¤Þ¤¹¡£
¡¡»öÁ°¤Ë·ÐÏ©¤ò¢ª¤Çɽ¼¨¤¹¤ëµ¡Ç½¤Ë¤Ï¡¢DOTween ¤ÎºÂɸ¤ÎÂå¤ï¤ê¤Ë¡¢NavMeshAgent ¤ÎºÂɸ¤òÍøÍѤ¹¤ë¤³¤È¤Ç¡¢¤¤¤Þ¤Þ¤Ç¤Î½èÍý¤òήÍѤ·¤Æ¤¤¤Þ¤¹¡£
¤³¤ì¤Ï¥á¥½¥Ã¥É¤Î°ú¿ô¤ËÅϤ¹¾ðÊó¤òÊѲ½¤µ¤»¤ë¤³¤È¤ÇÂбþ¤Ç¤¤Æ¤¤¤Þ¤¹¡£¥×¥í¥°¥é¥à¤Î¤è¤¤Éôʬ¤È¤¤¤¨¤Þ¤¹¡£
EnemyGenerator.cs
¡¡¥²¡¼¥à¤ò¼Â¹Ô¤·¡¢NavMeshAgent ¤Îµ¡Ç½¤Ë¤è¤ê¡¢Å¨¤¬°ÜÆ°¤¹¤ë¤³¤È¤ò³Îǧ¤¹¤ë¤È¤È¤â¤Ë¡¢
¾ã³²Êª¤Î¥ª¥Ö¥¸¥§¥¯¥È¤ò¥²¡¼¥àÆâ¤Ç°ÜÆ°¤µ¤»¤¿¤ê¡¢É½¼¨¤·¤¿¤ê¤·¤Æ·ÐÏ©¤òºÉ¤°¤è¤¦¤Ë¤·¤Þ¤¹¡£
¡¡ºÉ¤¤¤À¥¿¥¤¥ß¥ó¥°¤Ç¤Ï¤Ê¤¯¡¢Å¨¤¬¾ã³²Êª¤ËÀÜ¿¨¤·¤¿¥¿¥¤¥ß¥ó¥°¤Ç·ÐÏ©¾ðÊ󤬹¹¿·¤µ¤ì¤Æ¡¢¿·¤·¤¤·ÐÏ©¤Ë±è¤Ã¤Æ°ÜÆ°¤ò¤¹¤ë¤è¤¦¤Ë¤Ê¤ì¤ÐÀ©¸æÀ®¸ù¤Ç¤¹¡£
¡¡°Ê¾å¤Ç´°À®¤Ç¤¹¡£
- ¥«¥Æ¥´¥ê¡§
- ¿Ê³Ø/¥¹¥¯¡¼¥ë
- ¥×¥í¥°¥é¥ß¥ó¥°
¥³¥á¥ó¥È¤ò¤«¤¯