Unity¤Ë´ØÏ¢¤¹¤ëµ­»ö¤Ç¤¹

¡¡Å¨¤Î¾ðÊó¤òÀßÄꤷ¡¢À©¸æ¤¹¤ë¤¿¤á¤Î¥¯¥é¥¹¤ÎºîÀ®¤ò¹Ô¤¤¤Þ¤¹¡£

¡¡Å¨ÍѤΥ²¡¼¥à¥ª¥Ö¥¸¥§¥¯¥È¤òÇÛÃÖ¤·¤¿¤À¤±¤Ç¤Ï¡¢¤½¤ì¤¬¥²¡¼¥àÆâ¤Ë¤ª¤¤¤ÆŨ¤Ç¤¢¤ë¤Î¤«¤É¤¦¤«¤Ï¥×¥í¥°¥é¥à¤ÏȽÃǽÐÍè¤Þ¤»¤ó¡£
¤½¤³¤Ç¡¢Å¨ÍѤΥ²¡¼¥à¥ª¥Ö¥¸¥§¥¯¥ÈÍѤΥ¯¥é¥¹¤òºîÀ®¤·¡¢¤½¤ì¤ò¥¢¥¿¥Ã¥Á¤¹¤ë¤³¤È¤Ç¡¢¤½¤ÎŨÍѤΥ²¡¼¥à¥ª¥Ö¥¸¥§¥¯¥È¤¬
¥×¥í¥°¥é¥àÆâ¤Ë¤ª¤¤¤Æ¤â¡ÖŨ¤È¤·¤Æ¤ÎÌò³ä¡×¤ò»ý¤Ä¤è¤¦¤ËÀßÄꤷ¤Þ¤¹¡£



¼ê½ç£±£±¡¡¡¼Å¨¤ÎºîÀ®¡¼

¡¡¿·¤·¤¤³Ø½¬ÆâÍƤϡ¢°Ê²¼¤ÎÄ̤ê¤Ç¤¹¡£

¡ã³Ø½¬ÆâÍÆ¡ä
¡¡¡¦enum ¤Î¤ß¤Î¥¹¥¯¥ê¥×¥È
¡¡¡¦NavMeshAgent ¤ËÍÑ°Õ¤µ¤ì¤Æ¤¤¤ëÊÑ¿ô¤È¥á¥½¥Ã¥É
¡¡¡¦¥³¥ë¡¼¥Á¥ó¤òÊÑ¿ô¤ËÂåÆþ¤·¤Æ¼Â¹Ô¤¹¤ë
¡¡¡¦¥í¡¼¥«¥ë´Ø¿ô¤Î¼ÂÁõÎã



Àß·×


¡¡NavMeshAgent ¤Îµ¡Ç½¤òÍøÍѤ·¡¢Å¨¤ò¥×¥ì¥¤¥ä¡¼¤Î°ÌÃ֤˸þ¤«¤Ã¤Æ°ÜÆ°¤µ¤»¤ëµ¡Ç½¤ò¼ÂÁõ¤·¤Þ¤¹¡£

NavMeshAgent
¥Ê¥Ó¥²¡¼¥·¥ç¥ó¤È·Ðϩõº÷
¥Ê¥Ó¥á¥Ã¥·¥å¥¨¡¼¥¸¥§¥ó¥È


¾¤Ë¤âµ­»ö¤¬Â¿¤¯¤¢¤ê¤Þ¤¹¤Î¤Ç¡¢¼«Ê¬¤ÇÄ´¤Ù¤Æ¤ª¤­¤Þ¤·¤ç¤¦¡£



¡¡NavMeshAgent µ¡Ç½¤Î¾¡¢Å¨¤Î¾ðÊó¤ò´ÉÍý¤·¡¢À©¸æ¤µ¤»¤ë¤¿¤á¤Î¥¯¥é¥¹¤òºîÀ®¤·¤Æ¡¢Å¨¤Î¥²¡¼¥à¥ª¥Ö¥¸¥§¥¯¥È¤Ë¥¢¥¿¥Ã¥Á¤·¤Þ¤¹¡£

¡¡Ä̾ï¤ÎŨ¤È¥Ü¥¹¤Ç¤Ï°ÜÆ°ÊýË¡¤¬°Û¤Ê¤ë¤¿¤á¡¢¤³¤ì¤é¤ò»öÁ°¤Ë enum ¤ËÅÐÏ¿¤·¤Æ¤ª¤­¡¢¤½¤ì¤ò¸µ¤Ë NavMeshAgent ¤òµ¡Ç½¤µ¤»¤ë¤è¤¦¤ËÀ©¸æ¤·¤Þ¤¹¡£
NavMeshAgent ¤Î Agents ¤ÎÀßÄê¤È Bake ¤ÎÊýË¡¤Ë¤Ä¤¤¤Æ¤Ï³ä°¦¤·¤Æ¤¤¤Þ¤¹¤Î¤Ç¡¢¤Þ¤º¤Ï¡¢¤½¤Á¤é¤Î½àÈ÷¤ò¹Ô¤Ã¤Æ¤¯¤À¤µ¤¤¡£


Ũ¤Î¥²¡¼¥à¥ª¥Ö¥¸¥§¥¯¥È¤ÎÀßÄê¤ò¹Ô¤¦


¡¡NavMeshAgent ¤Îµ¡Ç½¤òÍøÍѤǤ­¤ë¤è¤¦¤Ë¤¹¤ë¤¿¤á¡¢¥¤¥ó¥¹¥Ú¥¯¥¿¡¼¤Î Add Component ¥Ü¥¿¥ó¤«¤é NavMeshAgent ¥³¥ó¥Ý¡¼¥Í¥ó¥È¤òÄɲä·¤Þ¤¹¡£
¤Þ¤¿¡¢Ray ¤Ë¤è¤ëȽÄê¤òÍ­¸ú¤Ë¤¹¤ë¤¿¤á¡¢¥³¥é¥¤¥À¡¼¤È Rigidbody ¤âÄɲä·¤Þ¤¹¡£¥³¥é¥¤¥À¡¼¤Î·Á¾õ¤ÏǤ°Õ¤Ç¤¹¤¬¡¢CapsuleCollider ¤¬¤è¤¤¤Ç¤·¤ç¤¦¡£


¡ãÀßÄêÎ㣱¡ä



¡ãÀßÄêÎ㣲¡ä



EnemyMoveType ¥¹¥¯¥ê¥×¥È¤òºîÀ®¤¹¤ë


¡¡Å¨¤Î°ÜÆ°ÊýË¡¤ò¹Í¤¨¤Æ¡¢»öÁ°¤Ë¼ïÎà¤È¤·¤Æ enum ¤ÎÎóµó»Ò¤ËÅÐÏ¿¤ò¹Ô¤Ã¤Æ¤ª¤­¤Þ¤¹¡£
¤³¤ì¤Ï»²¹Í»öÎã¤Ç¤¹¡£

¡¡º£²ó¤Ï enum ¤Î¤ß¤Î¥¹¥¯¥ê¥×¥È¤È¤·¤ÆºîÀ®¤·¤Æ¤¤¤Þ¤¹¡£
enum ¤Î¤ß¤Î¥¹¥¯¥ê¥×¥È¤Ï¡¢MonoBehaviour ¥¯¥é¥¹¤Î·Ñ¾µ¤¬¤¢¤ê¤Þ¤»¤ó¤Î¤Ç¡¢¥²¡¼¥à¥ª¥Ö¥¸¥§¥¯¥È¤Ë°Í¸¤·¤Þ¤»¤ó¡£¤Ä¤Þ¤ê¡¢¥¢¥¿¥Ã¥Á¤Ç¤­¤Þ¤»¤ó¡£
¤Ç¤¹¤¬¡¢¥¹¥¯¥ê¥×¥È¤òºîÀ®¤·¤¿Ãʳ¬¤Ç¡¢¤¹¤Ù¤Æ¤Î¥¹¥¯¥ê¥×¥ÈÆâ¤Ç¼«Í³¤ËÀë¸À¤·¤ÆÍøÍѤ¹¤ë¤³¤È¤¬¤Ç¤­¤Þ¤¹¡£



¡¡enum ¤Ç¤Ï¥²¡¼¥àÆâ¤ËÅо줵¤»¤¿¤¤¼ïÎà¤Î¾ðÊó¤ò¡¢Îóµó»Ò(¤ì¤Ã¤­¤ç¤·)¤È¤¤¤¦·Á¤Ç¼ïÎà¤òºîÀ®¤Ç¤­¤Þ¤¹¡£
º£²ó¤Ï¥¨¥Í¥ß¡¼¤Î°ÜÆ°¤Î¼ïÎà¤È¤¤¤¦¾ðÊó¤ò EnemyMoveType ¤È¤¤¤¦Ì¾Á°¤ÇºîÀ®¤·¡¢¤½¤ÎÃæ¤Ë ¥¨¥Í¥ß¡¼¤Î°ÜÆ°¤Î¼ïÎà ¤òÅÐÏ¿¤·¤Æ¤ª¤­¤Þ¤¹¡£
¤³¤ì¤ÏÄɲòÄǽ¤Ê¾ðÊó¤Ç¤¹¤Î¤Ç¡¢À衹¤Ë Ũ¤Î°ÜÆ°¤Î¼ïÎबÁý¤¨¤Æ¤âÂбþ¤Ç¤­¤Þ¤¹ ¡£


EnemyMoveType.cs

<= ¥¯¥ê¥Ã¥¯¤¹¤ë¤È³«¤­¤Þ¤¹¡£


¡¡¥¹¥¯¥ê¥×¥È¤òºîÀ®¤·¤¿¤é¥»¡¼¥Ö¤·¤Þ¤¹¡£



¡¡£³¤Ä°Ê¾å¤Î¾ðÊó¤ò´ÉÍý¤¹¤ë¾ì¹ç¤Ë¤Ï¡¢enum ¤Ç¤½¤Î¼ïÎà¤òÅÐÏ¿¤·¤Æ¤ª¤¯¤³¤È¤ò¤ª¤¹¤¹¤á¤·¤Þ¤¹¡£
enum ¤òÍøÍѤ¹¤ë¾ì¹ç¡¢¤½¤ÎÅÐÏ¿¤·¤Æ¤¢¤ëÎóµó»Ò¤«¤é¤·¤«¾ðÊó¤ò»ØÄê¤Ç¤­¤Þ¤»¤ó¤Î¤Ç¡¢
Î㤨¤Ð¡¢Ê¸»úÎó¤È°Û¤Ê¤ê¡¢»ØÄê¤ËºÝ¤·¤ÆÂǤÁ´Ö°ã¤¨¤¬È¯À¸¤·¤Þ¤»¤ó¤Î¤Ç¡¢ÉÔÈ÷¤ÎÃͤ¬Æþ¤ë¤³¤È¤âËɤ°¤³¤È¤¬½ÐÍè¤Þ¤¹¡£

¡¡¥²¡¼¥à¤ÎÆâÍƤ˱þ¤¸¤¿ enum ¤ò¹Í¤¨¤ÆºîÀ®¤·¤Æ±¿ÍѤ·¤Þ¤¹¡£
¥×¥ì¥¤¥ä¡¼¤Î¾õÂÖÍÑ(ÆÇ¡¢º®Íð¡¢áã¤ì¤È¤«)¡¢¥¢¥¤¥Æ¥à¤Î¼ïÎà(¾ÃÌ×ÉÊ¡¢Éð´ï¡¢Ëɶñ¡¢¤Ê¤É)¡¢
¥²¡¼¥à¤Î¾õÂÖ´ÉÍý(¥²¡¼¥à³«»ÏÁ°¡¢¥²¡¼¥àÃæ¡¢¥²¡¼¥à½ªÎ»¡Ë¤Ê¤É¡¢Èó¾ï¤Ë±þÍѤ¬Íø¤¯µ¡Ç½¤Ç¤¹¡£



¡¡¤Ê¤ª enum ¤Ç¤Ï³ÆÎóµó»Ò¤Ë¼«Æ°Åª¤ËÀ°¿ô¤ÎÈֹ椬Ϳ¤¨¤é¤ì¤Þ¤¹ ¡£°ìÈ־夫¤é 0 ¤ÇÏ¢È֤ˤʤäƤ¤¤Þ¤¹ ¡£
º£²ó¤Î¾ì¹ç¤Ç¤¢¤ì¤Ð¡¢Agent ¤Ë¤Ï 0¡¢Boss _1 ¤Ë¤Ï 2 ¤Î¿ô»ú¤¬Í¿¤¨¤é¤ì¤Æ¤¤¤Þ¤¹¡£

¡¡¤³¤ÎÈÖ¹æ¤Ï¸«¤¨¤Ê¤¤¾ðÊó¤Ç¤¹¤¬¡¢Îóµó»Ò¤ò int ·¿¤Ë¥­¥ã¥¹¥È¤ò¹Ô¤¦¤³¤È¤Ç¼èÆÀ¤·¤ÆÍøÍѽÐÍè¤Þ¤¹¡£
²¼µ­¤ÎÎã¤Î¾ì¹ç¡¢enumValue ¤Ë¤Ï 1 ¤¬ÂåÆþ¤µ¤ì¤Þ¤¹¡£

¡ãenum ¤ÎÎóµó»Ò¤Î¥­¥ã¥¹¥È¡ä
int  enumValue = (int)EnemyMoveType.Boss_0;

¡¡¤Þ¤¿¡¢Îóµó»Ò¤ÎÀë¸À»þ¤Ë¿ô»ú¤ò»ØÄꤷ¤ÆÂåÆþ¤¹¤ë¤³¤È¤â²Äǽ¤Ç¤¹¡£¤½¤Î¾ì¹ç¤Ë¤ÏÏ¢È֤ǤϤʤ¯¡¢»ØÄꤷ¤¿¿ôÃͤò¼èÆÀ½ÐÍè¤Þ¤¹¡£

¡ã¿ô»ú¤ÎÂåÆþ¤ÎÎã(º£²ó¤³¤ÎÊý¼°¤ÏÍøÍѤ·¤Þ¤»¤ó)¡ä
EnemyType.cs
public enum EnemyMoveType {
    Agent = 10,
    Boss_0 = 5,
    Boss_1 = 100
}

¡¡¾åµ­¤Î¤è¤¦¤ËÂåÆþ¤µ¤ì¤Æ¤¤¤ë¾ì¹ç¤Ë¤Ï¡¢Îóµó»Ò¤ò int ·¿¤Ë¥­¥ã¥¹¥È¤¹¤ë¤È¡¢ÂåÆþ¤·¤Æ¤¢¤ëÃͤ¬¼èÆÀ½ÐÍè¤Þ¤¹¡£
º£²ó¤Ï¿ô»ú¤ÎÂåÆþ¤Ï¹Ô¤Ã¤Æ¤¤¤Þ¤»¤ó¤Î¤Ç°ìÈÖ¾å¤ÎÎóµó»Ò¤Ë¤Ï 0 ¤«¤é½çÈ֤˺ÎÈÖ¤µ¤ì¤Æ¤¤¤Þ¤¹¡£


EnemyController ¥¹¥¯¥ê¥×¥È¤òºîÀ®¤¹¤ë


¡¡Å¨¤Î¥²¡¼¥à¥ª¥Ö¥¸¥§¥¯¥È¤Ë¥¢¥¿¥Ã¥Á¤·¤Æ¡¢Å¨¤Î¾ðÊó¤ä¡¢NavMeshAgent ¤ÎÀ©¸æ¤ò¹Ô¤¦¤¿¤á¤Î¥¹¥¯¥ê¥×¥È¤òºîÀ®¤·¤Þ¤¹¡£
½èÍý¤ÎÆâÍƤ¬Â¿¤¯¡¢Ê£»¨¤Ê¥í¥¸¥Ã¥¯¤Ë¤Ê¤Ã¤Æ¤¤¤Þ¤¹¤Î¤Ç¡¢ÊÑ¿ô¤ÎÀë¸À¤â´Þ¤á¤Æ¡¢¤·¤Ã¤«¤ê¤ÈÆɤ߲ò¤±¤ë¤è¤¦¤Ë¤·¤Æ¤¯¤À¤µ¤¤¡£


EnemyController.cs

<= ¥¯¥ê¥Ã¥¯¤¹¤ë¤È³«¤­¤Þ¤¹¡£



¡ãNavMeshAgent ¤ËÍÑ°Õ¤µ¤ì¤Æ¤¤¤ëÊÑ¿ô¤È¥á¥½¥Ã¥É¡ä


¡¡NavMeshAgent ¥¯¥é¥¹¤Ë¤Ï¿¤¯¤ÎÊÑ¿ô¤È¥á¥½¥Ã¥É¤¬ÍÑ°Õ¤µ¤ì¤Æ¤¤¤Þ¤¹¡£
¤³¤Îµ¡Ç½¤ò¾å¼ê¤¯³èÍѤ¹¤ë¤³¤È¤Ë¤è¤ê¡¢AI ¤Ë¤è¤ë NavMeshAgent ¤Î¥ë¡¼¥È¤Î¼«Æ°°ÜÆ°¤ò¼ÂÁõ¤¹¤ë¤³¤È¤¬¤Ç¤­¤Þ¤¹¡£

¡¡NavMeshAgent ·¿¤ò¥¹¥¯¥ê¥×¥ÈÆâ¤ÇÀë¸À¤·¡¢³ÆÊÑ¿ô¤ä¥á¥½¥Ã¥É¤òÍøÍѤ¹¤ë¤¿¤á¤Ë¤Ï using UnityEngine.AI; ¤ÎÀë¸À¤¬É¬ÍפǤ¹¡£


£±¡¥NavMeshAgent.destination ÊÑ¿ô

¡¡NavMeshAgent ÌÜɸÃÏÅÀ¤òÀßÄꤹ¤ë¤³¤È¤¬¤Ç¤­¤ë Vector3 ·¿¤ÎÊÑ¿ô¤Ç¤¹¡£
¤³¤Î¾ðÊó¤ò¥»¥Ã¥È¤¹¤ë¤³¤È¤Ç¡¢NavMeshAgent ¤ËÌÜŪÃϤذÜÆ°¤¹¤ë¤³¤È¤òÅÁ¤¨¡¢°ÜÆ°¤ò³«»Ï¤µ¤»¤ë¤³¤È¤¬¤Ç¤­¤Þ¤¹¡£

¡ã»²¹Í¥µ¥¤¥È¡ä
Unity ¸ø¼°¥¹¥¯¥ê¥×¥È¥ê¥Õ¥¡¥ì¥ó¥¹
NavMeshAgent.destination
https://docs.unity3d.com/jp/current/ScriptReferenc...
Unity ¸ø¼°¥Þ¥Ë¥å¥¢¥ë
NavMeshAgent ¤ËÌÜŪÃϤذÜÆ°¤¹¤ë¤³¤È¤òÅÁ¤¨¤ë
https://docs.unity3d.com/ja/current/Manual/nav-Mov...


£²¡¥NavMeshAgent.speed ÊÑ¿ô

¡¡NavMeshAgent ¤Ë¤è¤ë¥ë¡¼¥È°ÜÆ°»þ¤ÎºÇÂç®ÅÙ¤ÎÀßÄêÃͤǤ¹¡£0 ¤Ë¤¹¤ë¤³¤È¤Ç°ÜÆ°¤ÏÄä»ß¤·¤Þ¤¹¡£


¡ã»²¹Í¥µ¥¤¥È¡ä
Unity ¸ø¼°¥¹¥¯¥ê¥×¥È¥ê¥Õ¥¡¥ì¥ó¥¹
NavMeshAgent.speed
https://docs.unity3d.com/jp/current/ScriptReferenc...


£³¡¥NavMeshAgent.ResetPath ¥á¥½¥Ã¥É

¡¡NavMeshAgent ¤Ë¤è¤ë¥ë¡¼¥È¤ÎÀßÄê¾ðÊó¤òºï½ü¤·¤Þ¤¹¡£
¤³¤ì¤Ë¤è¤ê¡¢°ÜÆ°Àè¤ÎÃÏÅÀ¤Î¾ðÊ󤬤ʤ¯¤Ê¤ë¤¿¤á¡¢ºÆÅÙ¡¢ÌÜŪÃϤξðÊó¤¬ÀßÄꤵ¤ì¤ë¤Þ¤Ç NavMeshAgent ¤Ï°ÜÆ°¤òÄä»ß¤·¤Þ¤¹¡£


¡ã»²¹Í¥µ¥¤¥È¡ä
Unity ¸ø¼°¥¹¥¯¥ê¥×¥È¥ê¥Õ¥¡¥ì¥ó¥¹
NavMeshAgent.ResetPath
https://docs.unity3d.com/jp/current/ScriptReferenc...


¥³¥ë¡¼¥Á¥ó¤òÊÑ¿ô¤ËÂåÆþ¤·¤Æ¼Â¹Ô¤¹¤ë


¡¡°Ê²¼¤Î¥Ú¡¼¥¸¤Ë¾ÜºÙ¤ÊÀâÌÀ¤¬¤¢¤ê¤Þ¤¹¡£

¡¡=>¡¡¥³¥ë¡¼¥Á¥ó¤òÊÑ¿ô¤ËÂåÆþ¤·¤Æ¼Â¹Ô¤¹¤ë

¡¡º£²ó¤Î¥±¡¼¥¹¤Ç¤Ï¡¢Å¨¤¬¥×¥ì¥¤¥ä¡¼¤ò¸«¼º¤Ã¤¿¤ê¡¢Å¨¤Î¹¶·â½èÍý¤ÎÅÓÃæ¤ÇŨ¤¬Åݤµ¤ì¤¿¾ì¹ç¤Ë¡¢¹¶·â¤Î½àÈ÷¤Î½èÍý¤òÄä»ß¤Ç¤­¤ë¤è¤¦¤Ë¤¹¤ë¤¿¤á¤Ë¤³¤Îµ¡Ç½¤ò¼ÂÁõ¤·¤Æ¤¤¤Þ¤¹¡£

¡¡¥³¥ë¡¼¥Á¥ó¥á¥½¥Ã¥É¤ò¼Â¹Ô¤·¤Æ¤¤¤ë¥¹¥¯¥ê¥×¥È¤¬¥¢¥¿¥Ã¥Á¤µ¤ì¤Æ¤¤¤ë¥²¡¼¥à¥ª¥Ö¥¸¥§¥¯¥È¤¬ÇË´þ¤µ¤ì¤¿¾ì¹ç¡¢
¥³¥ë¡¼¥Á¥ó¥á¥½¥Ã¥É¤Î½èÍý¤â¶¯À©Åª¤ËÄä»ß¤µ¤ì¤Þ¤¹¡£¤½¤Î¤¿¤á¡¢¼ç¤ÊÌÜŪ¤È¤·¤Æ¤Ï¡¢Å¨¤¬¥×¥ì¥¤¥ä¡¼¤ò¸«¼º¤Ã¤¿¾ì¹ç¤Ë¡¢¹¶·â½àÈ÷½èÍý¤òÄä»ß¤µ¤»¤ë¤³¤È¤Ç¤¹¡£

¡¡¥³¥ë¡¼¥Á¥ó¥á¥½¥Ã¥É¤ÏÈóƱ´ü½èÍý¤Ç¤¢¤ë¤¿¤á¡¢¤½¤ì°Ê³°¤Î½èÍý¤¬½ª¤ï¤ë¤Î¤òÂÔ¤¿¤º¤Ë¡¢¥³¥ë¡¼¥Á¥ó¥á¥½¥Ã¥ÉÆâ¤Î½èÍý¤ò¿Ê¤á¤Æ¤¤¤­¤Þ¤¹¡£
ÊØÍø¤Ç¤¢¤ëÈ¿ÌÌ¡¢¥³¥ë¡¼¥Á¥ó¥á¥½¥Ã¥É¤Î½èÍý¤¬ÉÔÍפˤʤ俾ì¹ç¤Ë¤Ï¤·¤Ã¤«¤ê¤ÈÄä»ß¤¹¤ëɬÍפ¬¤¢¤ê¤Þ¤¹¡£


¡ãÊÑ¿ô¤Ë¥³¥ë¡¼¥Á¥ó¥á¥½¥Ã¥É¤òÅÐÏ¿¤·¤Æ¼Â¹Ô¡ä

    ¡¡¡¡private IEnumerator attackCoroutine;   // ¥³¥ë¡¼¥Á¥ó¥á¥½¥Ã¥É¤òÅÐÏ¿¤¹¤ë¤¿¤á¤ÎÊÑ¿ô


        void SetAttackCoroutine() {

            // ¹¶·âÍѤΥ᥽¥Ã¥É¤òÂåÆþ¤·¤ÆÅÐÏ¿
            attackCoroutine = Attack(player);

            // ÅÐÏ¿¤·¤¿¥á¥½¥Ã¥É¤ò¼Â¹Ô
            StartCoroutine(attackCoroutine);

            Debug.Log("¹¶·â³«»Ï");
        }



¡ãÊÑ¿ô¤ËÅÐÏ¿¤µ¤ì¤Æ¤¤¤ë¥³¥ë¡¼¥Á¥ó¥á¥½¥Ã¥É¤òÄä»ß¡ä
¡¡¡¡StopCoroutine(attackCoroutine);

»²¹Í¥µ¥¤¥È
Qiita @riekure ÍÍ
¡ÚUnity¡ÛÈóƱ´ü½èÍý¤òÍý²ò¤¹¤ë¡Á¥³¥ë¡¼¥Á¥óÊÔ¡Á
https://qiita.com/riekure/items/9f59fec68c3e31f38f...


¡ã¥í¡¼¥«¥ë´Ø¿ô¡ä


¡¡C# 7.0 °Ê¹ß¤Ç¤Ï¥á¥½¥Ã¥É¤ÎÆâÉô¤ËÆþ¤ì»Ò¤È¤·¤Æ¥á¥½¥Ã¥É¤òºîÀ®½ÐÍè¤ë¤è¤¦¤Ë¤Ê¤Ã¤Æ¤¤¤Þ¤¹¡£
¥á¥½¥Ã¥ÉÆâÉô¤ËÀë¸À¤¹¤ë¥á¥½¥Ã¥É¤ò¥í¡¼¥«¥ë´Ø¿ô¤È¸Æ¤Ó¤Þ¤¹¡£

¡¡¥á¥½¥Ã¥ÉÆâ¤ÎÆþ¤ì»Ò¤Ç¤¢¤ë´Ø¿ô¤Ç¤¢¤ë¤¿¤á¡¢½¤¾þ»Ò¤ÎÀë¸À¤Ï½ÐÍè¤Þ¤»¤ó(private ¤Î¤ß)¤¬°ú¿ô¤âÌá¤êÃͤâ»ý¤¿¤»¤ë¤³¤È¤¬½ÐÍè¤Þ¤¹¡£
C# 8.0 °Ê¹ß¤Ç¤Ï¡¢Â°À­¤òÉÕÍ¿¤·¤¿¤ê¤¹¤ë¤³¤È¤â½ÐÍè¤Þ¤¹¡£


¡ãÈ´¿è¡ä
    private void OnTriggerStay(Collider other) {
        if (isAttack) {
            return;
        }

        // ¥×¥ì¥¤¥ä¡¼¤Î¾ðÊó¤òÊÝ»ý¤·¤Æ¤ª¤ê¡¢¹¶·âÃæ¤Ç¤Ê¤¤¤Ê¤é
        if (player != null) {

            // ¥í¡¼¥«¥ë´Ø¿ô¤ò¼Â¹Ô
            SetAttackCoroutine();
        }

        // ¥í¡¼¥«¥ë´Ø¿ô¤òÄêµÁ
        void SetAttackCoroutine() {

            // IEnumerator ·¿¤ÎÊÑ¿ô¤Ë¹¶·âÍѤΥ᥽¥Ã¥É¤òÅÐÏ¿
            attackCoroutine = Attack(player);

            // ÅÐÏ¿¤·¤¿¥á¥½¥Ã¥É¤ò¼Â¹Ô
            StartCoroutine(attackCoroutine);

            Debug.Log("¹¶·â³«»Ï");
        }


¡¡¥í¡¼¥«¥ë´Ø¿ô¤ÏÄ̾ï¤Î´Ø¿ô¤ÈƱ¤¸¤è¤¦¤Ë¡¢¼Â¹ÔÌ¿Îá¤ò¹Ô¤¦¤³¤È¤Ç¼Â¹Ô¤µ¤ì¤Þ¤¹¡£
¤¿¤À¤·¡¢ÍøÍѤ¹¤ëÈÏ°Ï(¥¹¥³¡¼¥×)¤¬¡¢¥í¡¼¥«¥ë´Ø¿ô¤¬ÄêµÁ¤µ¤ì¤Æ¤¤¤ë¥á¥½¥Ã¥ÉÆâÉô¤Î¤ß¤Ë¸Â¤é¤ì¤Þ¤¹¡£

¡¡º£²ó¤Î¥±¡¼¥¹¤Ç¤¢¤ì¤Ð¡¢SetAttackCoroutine ¥á¥½¥Ã¥É¤ò OnTriggerStay ¥á¥½¥Ã¥ÉÆâ¤ÇÀë¸À¤·¤Æ¤¤¤Þ¤¹¤Î¤Ç¡¢
SetAttackCoroutine ¥á¥½¥Ã¥É¤ò¸Æ¤Ó½Ð¤¹Ì¿Îá¤Ï¡¢OnTriggerStay ¥á¥½¥Ã¥ÉÆâ¤Ç¤·¤«¼Â¹Ô¤Ç¤­¤Þ¤»¤ó¡£

¡¡ÍøÍÑÊýË¡¤È¤·¤Æ¤Ï¡¢¥á¥½¥Ã¥É¤Î¸Æ¤Ó½Ð¤·Ì¿Î᤬ÆÃÄê¤Î¥á¥½¥Ã¥ÉÆâ¤Ë¤Î¤ß¤Ë¤¢¤ê¡¢¤«¤Ä¡¢Â¾¤Î¥á¥½¥Ã¥É¤«¤é¤â¸Æ¤Ð¤ì¤ë¤³¤È¤Î¤Ê¤¤½èÍý¤ò¥í¡¼¥«¥ë´Ø¿ô¤È¤·¤Æ½àÈ÷¤¹¤ë¤³¤È¤¬°ìÈÌŪ¤Ç¤¹¡£
ÍøÍÑÈϰϤòÀ©¸Â¤·¤Æ¤¤¤ëʬ¡¢½èÍý¤¬Æɤߤ䤹¤¯¤Ê¤ê¤Þ¤¹¤·¡¢¥¨¥é¡¼¤â¸«¤Ä¤±¤ä¤¹¤¯¤Ê¤ê¤Þ¤¹¡£(»È¤¤Æ»¤¬¸Â¤é¤ì¤Æ¤¤¤ë½èÍý¤ò¥á¥½¥Ã¥É²½¤·¡¢¥á¥½¥Ã¥ÉÆâÉô¤ËÊĤ¸¹þ¤á¤Æ¤ª¤¯¤³¤È¤Ç²ÄÆÉÀ­¤¬¾å¤¬¤ê¤Þ¤¹¡£)

MicroSoft
¥í¡¼¥«¥ë´Ø¿ô
https://docs.microsoft.com/ja-jp/dotnet/csharp/pro...
.NET column ÍÍ
C#¤Î¥í¡¼¥«¥ë´Ø¿ô¤È¤Ï¡©»È¤¤Êý¤ä¥á¥ê¥Ã¥È¡¦¥é¥à¥À¼°¤È¤Î°ã¤¤¤â¾Ò²ð
https://www.fenet.jp/dotnet/column/language/3933/


Ũ¤Î¥²¡¼¥à¥ª¥Ö¥¸¥§¥¯¥È¤Ë EnemyCotroller ¥¹¥¯¥ê¥×¥È¤ò¥¢¥¿¥Ã¥Á¤·¤ÆÀßÄê¤ò¹Ô¤¦


¡¡Å¨¤Î¥²¡¼¥à¥ª¥Ö¥¸¥§¥¯¥È¤Ë EnemyController ¥¹¥¯¥ê¥×¥È¤ò¥¢¥¿¥Ã¥Á¤·¤ÆÀßÄê¤ò¹Ô¤¤¤Þ¤¹¡£

¡¡lookTarget ÊÑ¿ô¤Ï None¡Ênull¡Ë ¤Î¤Þ¤Þ¤ÇÌäÂꤢ¤ê¤Þ¤»¤ó¡£¤³¤Á¤é¤Ë¤Ï¡¢¥²¡¼¥à¤Î¼Â¹Ô¸å¤Ë¥×¥ì¥¤¥ä¡¼¤Î¾ðÊó¤ò¼èÆÀ¤¹¤ë¤è¤¦¤Ë¤Ê¤Ã¤Æ¤¤¤Þ¤¹¡£

¡¡enemyNo ÊÑ¿ô¤Ï 0 ¤Ç¤¹¡£¤½¤ì°Ê³°¤Î¡¢hp¡¢ attackPower¡¢ moveSpeed ¤Î³ÆÊÑ¿ô¤Ë¤Ä¤¤¤Æ¤Ï¡¢²¼µ­¤Î²èÁü¤ò»²¹Í¤Ë¤·¤Ê¤¬¤éǤ°Õ¤ÎÃͤòÀßÄꤷ¤Æ¤¯¤À¤µ¤¤¡£


¡ã¥¤¥ó¥¹¥Ú¥¯¥¿¡¼²èÁü¡ä


¡¡ÀßÄ꤬´°Î»¤·¤¿¤é¡¢¥×¥ì¥Õ¥¡¥Ö¤Ë¤·¤Æ¤ª¤­¤Þ¤¹¡£
¼¡¤Î¼ê½ç¤Ç¤â¤³¤Î¥²¡¼¥à¥ª¥Ö¥¸¥§¥¯¥È¤ÏÍøÍѤ¹¤ë¤Î¤Ç¡¢¥Ò¥¨¥é¥ë¥­¡¼¤«¤é¤Ïºï½ü¤»¤º¤Ë¤ª¤­¤Þ¤¹¡£



¡¡°Ê¾å¤Ç¤³¤Î¼ê½ç¤Ï½ªÎ»¤Ç¤¹¡£

¡¡=>¡¡¼¡¤Ï¡¡¼ê½ç£±£²¡¡¡¼Å¨¤Ø¤Î¥À¥á¡¼¥¸È½Ä굡ǽ¡¼¡¡¤Ç¤¹¡£

¥³¥á¥ó¥È¤ò¤«¤¯


¡Öhttp://¡×¤ò´Þ¤àÅê¹Æ¤Ï¶Ø»ß¤µ¤ì¤Æ¤¤¤Þ¤¹¡£

ÍøÍѵ¬Ìó¤ò¤´³Îǧ¤Î¤¦¤¨¤´µ­Æþ²¼¤µ¤¤

Menu


´ðÁÃ

µ»½Ñ/Ãμ±(¼ÂÁõÎã)

3D¥¢¥¯¥·¥ç¥ó¥²¡¼¥à

2D¤ª¤Ï¤¸¤­¥²¡¼¥à(ȯŸÊÔ)

2D¶¯À©²£¥¹¥¯¥í¡¼¥ë¥¢¥¯¥·¥ç¥ó(ȯŸÊÔ)

2D¥¿¥Ã¥×¥·¥å¡¼¥Æ¥£¥ó¥°(³ÈÄ¥ÊÔ)

¥ì¡¼¥¹¥²¡¼¥à(È´¿è)

2DÊüÃÖ¥²¡¼¥à(ȯŸÊÔ)

3D¥ì¡¼¥ë¥¬¥ó¥·¥å¡¼¥Æ¥£¥ó¥°(±þÍÑÊÔ)

3Dæ½Ð¥²¡¼¥à(È´¿è)

2D¥ê¥¢¥ë¥¿¥¤¥à¥¹¥È¥é¥Æ¥¸¡¼

3D¥¿¥Ã¥×¥¢¥¯¥·¥ç¥ó(NavMeshAgent »ÈÍÑ)

2D¥È¥Ã¥×¥Ó¥å¡¼¥¢¥¯¥·¥ç¥ó(¥«¥¨¥ë¤Î°Ù¤Ë¡Á¡¢¥Ü¥³¥¹¥«¥¦¥©¡¼¥ºÉ÷)

VideoPlayer ¥¤¥Ù¥ó¥ÈϢư¤Î¼ÂÁõÎã

VideoPlayer ¥ê¥¹¥ÈÆ⤫¤é¥à¡¼¥Ó¡¼ºÆÀ¸¤Î¼ÂÁõÎã(ȯŸ)

AR ²èÁüÉÕ¤­¥ª¥Ö¥¸¥§¥¯¥ÈÀ¸À®¤Î¼ÂÁõÎã

AR ¥ê¥¹¥ÈÆ⤫¤éÀ¸À®¤Î¼ÂÁõÎã(ȯŸ)

2D¥È¥Ã¥×¥Ó¥å¡¼¥¢¥¯¥·¥ç¥ó(¥µ¥Ð¥¤¥Ð¡¼É÷)

private



¤³¤Î¥µ¥¤¥ÈÆâ¤ÎºîÉʤϥæ¥Ë¥Æ¥£¤Á¤ã¤ó¥é¥¤¥»¥ó¥¹¾ò¹à¤Î¸µ¤ËÄ󶡤µ¤ì¤Æ¤¤¤Þ¤¹¡£

´ÉÍý¿Í/Éû´ÉÍý¿Í¤Î¤ßÊÔ½¸¤Ç¤­¤Þ¤¹