ãUnity7ãæµãã£ã©ã¯ã¿ã¼ã®ã¹ã¯ãªãããä½æãããï¼ã2Dãã¼ã°ã©ã¤ã¯10ã
Unity5.0.0f4 Personal(2015å¹´6æ)
Â
ååã®ç¶ãã§ãã
Â
ä»åã¯ãEnemyã«ä»ããã¹ã¯ãªãããä½æãã¦ããã¾ãã
Enemyã®ç§»åãPlayerã¸ã®æ»æãªã©ã®æ©è½ãå®è£ ãã¾ãã
Â
ãç®æ¨ãæµãã£ã©ã¯ã¿ã¼ã®ã¹ã¯ãªãããä½æãã
Â
2D Roguelike 10 of 14 : Enemy Script - YouTube
Â
Enemyã¨ããååã®ã¹ã¯ãªãããScriptsãã©ã«ãã«ä½æããä¸èº«ãæ¸ãã¦ããã¾ãã以ä¸ã½ã¼ã¹ã§ãã
Â
Â
Startã¡ã½ãã
 ã¾ãã¯Startã¡ã½ããã§ããoverride修飾åãä»ãã¦ããã®ã§ãMovingObjectã¯ã©ã¹ã®Startã¡ã½ãããç¶æ¿ãã¦ãã¾ãã
Â
å§ãã«Animatorããã£ãã·ã¥ãã¦ããã¾ãã
Â
次ã«ã¿ã°ããPlayerãã®ãªãã¸ã§ã¯ãã®Transformæ å ±ãåå¾ãã¾ãã
Â
æå¾ã«ç¶æ¿ããMovingObjectã¯ã©ã¹ã®Startã¡ã½ããããbaseã使ãå¼ã³åºãã¦ãã¾ãã
Â
Â
ç¶æ¿å ã¯ãã¡ãã®è¨äºã§ä½æãã¦ãã¾ãã
Â
Â
MoveEnemyã¡ã½ãã
ãã¡ãã®ã¡ã½ããã§Enemyãèªåçã«ãã¬ã¤ã¤ã¼ãç®æãã¦åãæ©è½ãå®è£ ãã¦ãã¾ããAIã§ããã
Â
ã¾ãã¯xã¨yã®ä½ç½®ãä¿åããå¤æ°xDirãyDirãä½æãã¦ããã¾ãã
Â
ç¶ãã¦ãã¬ã¤ã¤ã¼ã®ç¾å¨ã®position.xããEnemyã®ç¾å¨ã®positiona.xããã¤ãã¹ããã§ã¦ããä½ç½®æ å ±ã絶対å¤ã«å¤æ´ãã¾ãããã®å¤ãEpsilon(0ã«éããªãè¿ãæ°)ãããå°ããæãã¤ã¾ã0ã®æã«ifæã®ä¸ã«å ¥ã£ã¦ããã¾ãã
position.xå士ãå¼ãã絶対å¤ã0ã®æã¨ããã®ã¯ãã¤ã¾ãEnemyã®ä¸ãä¸ã«ãã¬ã¤ã¤ã¼ãããã¨ãããã¨ã§ãã
Â
ifæã®ä¸ã§ã¯ãä»åº¦ã¯ãã¬ã¤ã¤ã¼ã®position.yã¨Enemyã®position.yã®å¤§ãããæ¯è¼ãããã¬ã¤ã¤ã¼ã®ã»ãã大ãããã°yDirã«1ããEnemyã®ã»ãã大ãããã°-1ãä»£å ¥ãã¦ãã¾ãã
Â
ãã¬ã¤ã¤ã¼ãEnemyã®ä¸ä¸ã«ããªãå ´åãelseæã®ä¸ã«å ¥ãã¾ãããã¬ã¤ã¤ã¼ã®position.xã¨Enemyã®position.xã®å¤§ãããæ¯è¼ãããã¬ã¤ã¤ã¼ã®ã»ãã大ãããã¤ã¾ããã¬ã¤ã¤ã¼ãå³ã«ããã°xDirã«1ããEnemyã®ã»ãã大ãããã¤ã¾ããã¬ã¤ã¤ã¼ãå·¦ã«ããã°-1ãä»£å ¥ãã¦ãã¾ãã
Â
ãããã®å¤ãå¼æ°ã«ãã¦ãAttemptMoveã¡ã½ãããå¼ã³åºãã¦ãã¾ããAttemptMoveã¡ã½ããã¯ã¸ã§ããªãã¯ã§ãããããåå¼æ°ãPlayerããæå®ãã¦ãã¾ãã
Â
Â
AttemptMoveã¡ã½ãã
AttemptMoveã¡ã½ãããMovingObjectã¯ã©ã¹ãç¶æ¿ãã¦ãã¾ããã¾ããã¸ã§ããªãã¯ã¨ãã¦Playeråãããã£ã¦ãã¾ãã
Â
ã¾ãã¯ããã«skipMoveå¤æ°ãtrueã§ããæãskipMoveãfalseã«ããã¡ã½ãããçµäºãã¦ãã¾ãã
Completedã«ããã²ã¼ã ã楽ããã 人ã¯åããã¨æãã¾ããããã®ã²ã¼ã ã¯ãã¬ã¤ã¤ã¼ã2åè¡åããå¾ãEnemyã1åè¡åããã¨ããæµãã¨ãªã£ã¦ãã¾ãããããå®ç¾ãããããã«ãEnemyã®è¡åã1åã¹ããããã¦ããã¨ããããã§ãã
Â
ç¶ãã¦ç¶æ¿ããAttemptMoveãå¼ã³åºãã¦ãã¾ãã<T>ã«ã¯Playeråãå ¥ããå¼æ°ã¨ãã¦MoveEnemyã¡ã½ããã§åºããxDirã¨yDirãæå®ãã¦ãã¾ãã
ããã§2ã¿ã¼ã³ã«1度ããã¬ã¤ã¤ã¼ã«åãã¦åãã¨ããå¦çãå®ç¾ãã¾ããã
Â
ã¡ã½ããã®æå¾ã§skipMoveãtrueã«ãã¾ããã®ã§ã次ã®ã¿ã¼ã³ã¯ã¹ãããããã¾ãã
Â
OnCantMoveã¡ã½ãã
ç¶æ¿å ã®AttemptMoveã¡ã½ããã«ã¦ãEnemyããã¬ã¤ã¤ã¼ã«æ¥è§¦ããæã«å¼ã³åºãããã¡ã½ããã§ãã
Â
ã¾ãæåã«hitPlayerå¤æ°ã使ã£ã¦ãPlayerã¯ã©ã¹ãåå¾ãã¦ãã¾ãã
Â
次ã«Playerã¯ã©ã¹ã®LoseFoodã¡ã½ãããå¼ã³åºãã¦ãã¾ããå¼æ°ã«ã¯ãã¡ã¼ã¸ãæå®ããã¾ãã
Â
ä»åã¯ããã¾ã§ã§ãã
ãããã¨ããããã¾ããã
Â
ãUnityéçº7ãã¢ãã¡ã¼ã·ã§ã³ãä½ãããï¼ã2Dãã¼ã°ã©ã¤ã¯2ã
ãUnityéçº7ãFloorãã¢ã¤ãã ãä½æãããï¼ã2Dãã¼ã°ã©ã¤ã¯3ã
ãUnityéçº7ãBoardManagerãå¼ã³åºãGameManagerãä½æããã2Dãã¼ã°ã©ã¤ã¯5ã
ãUnityéçº7ãç ´å£å¯è½ãªå£(Wall)ãä½æãããï¼ããã¼ã°ã©ã¤ã¯7ã
ãUnityéçº7ããã¬ã¤ã¤ã¼ã®ã¢ãã¡ã¼ã¿ã¼ãè¨å®ãããï¼ããã¼ã°ã©ã¤ã¯8ã
ãUnityéçº7ããã¬ã¤ã¤ã¼ç¨ã®ã¹ã¯ãªãããè¨å®ãããï¼ããã¼ã°ã©ã¤ã¯9ã
ãUnityéçº7ãBGMã¨å¹æé³ãä»ããã2Dãã¼ã°ã©ã¤ã¯13ã
ãUnityéçº7ãã¿ããããã«ã«å¯¾å¿ããããï¼ã2Dãã¼ã°ã©ã¤ã¯14(Fin)ã
Â