-
Notifications
You must be signed in to change notification settings - Fork 1
/
PathfinderDemo.cs
36 lines (30 loc) · 961 Bytes
/
PathfinderDemo.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using TilePathFinder;
public class PathfinderDemo : MonoBehaviour
{
public Grid TileGrid;
public Pathfinder pathFinder;
void Start()
{
pathFinder = new Pathfinder(TileGrid, "Blocking", "Floor");
}
void Update()
{
if (Input.GetMouseButtonDown(0))
{
Vector3 mousePos = Camera.main.ScreenToWorldPoint(Input.mousePosition);
Vector3Int endPoint = TileGrid.WorldToCell(mousePos);
Vector3Int startPoint = TileGrid.WorldToCell(transform.position);
List<Vector3Int> path = pathFinder.FindPath(startPoint, endPoint);
int steps = 0;
foreach (Vector3Int step in path)
{
steps++;
Debug.Log("step " + steps + ": (" + step.x + "," + step.y + ")");
transform.position = step;
}
}
}
}