Esempio n. 1
0
    // If the heuristic = 2f, the movement is diagonal
    public float Cost(Vector3Int a, Vector3Int b)
    {
        if (Math.Abs(AStarSearch.Heuristic(a, b) - 2f) < 0.001f)
        {
            return((int)tiles[b.x, b.y] * Mathf.Sqrt(2f));
        }


        return((int)tiles[b.x, b.y] == 0 || LevelManager.Instance.activeEnemies.Any(e => e.tilePos == new Vector3Int(b.x, b.y, 0)) ? 999999 : (int)tiles[b.x, b.y]);
    }
Esempio n. 2
0
 protected override void MoveEnd()
 {
     base.MoveEnd();
     //弹出命令选择框
     enemyList.Clear();
     foreach (var enemy in GameObject.FindGameObjectsWithTag("Enemy"))
     {
         if (AStarSearch.Heuristic(enemy.transform.position, transform.position) <= Attack_Range)
         {
             enemyList.Add(enemy.GetComponent <Enemy>());
         }
     }
     if (enemyList.Count > 0)
     {
         CommandBox._ins.Show(this, Command.Attack, Command.AwaitOrders);
     }
     else
     {
         CommandBox._ins.Show(this, Command.AwaitOrders);
     }
 }