/// <summary> /// 轮询。 /// </summary> void Update() { // 如果鼠标左键按下 if (Input.GetMouseButtonDown(0)) { // 获得鼠标的屏幕坐标 Vector3 mousePosition = Input.mousePosition; // 得到鼠标的世界坐标 Vector3 mouseWorldPosition = Camera.main.ScreenToWorldPoint(mousePosition); // 得到鼠标的Tile坐标 Vector3Int mapCellPosition = m_TileMap.WorldToCell(mouseWorldPosition); // 如果该坐标合法(不越界、不是障碍物) if (m_AStarUnityTile.CheckValid(mapCellPosition)) { // 如果设置点的机会还剩2次(代表将要设置开始点) if (m_SetPointChance == 2) { m_StartNode = new AStarNode(mapCellPosition.y, mapCellPosition.x); m_AStarUnityTile.MarkNode(m_StartNode, 3); } // 否则如果设置点的机会只剩1次(代表将要设置目标点) else if (m_SetPointChance == 1) { m_EndNode = new AStarNode(mapCellPosition.y, mapCellPosition.x); m_AStarUnityTile.MarkNode(m_EndNode, 4); } // 设置后要将机会减一 m_SetPointChance--; } } }
public override void Do() { m_tool.MarkNode(m_actor, 7); }