using System.Collections;
using System.Collections.Generic;
using UnityEngine;
publicclass Point{
public Point Parent { get; set; }
publicfloat F { get; set; }
publicfloat G { get; set; }
publicfloat H { get; set; }
publicint x { get; set; }
publicint y { get; set; }
publicbool isWall { get; set; }
publicPoint(int x, int y, Point parent=null)
{
this.x = x;
this.y = y;
Parent = parent;
isWall = false;
}
///<summary>/// 更新父节点、g和f、值///</summary>///<param name="parent"></param>///<param name="g"></param>publicvoidUpdateParent(Point parent, float g)
{
Parent = parent;
G = g;
F = G + H;
}
}
3. 创建Astar类实现寻路
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
publicclass AStar : MonoBehaviour
{
// Use this for initializationvoid Start()
{
InitMap();
Point start = map[2, 3];
Point end = map[6, 3];
FindPath(start, end);
ShowPath(start, end);
}
privateconstint mapWith = 15;
privateconstint mapHeigh = 15;