cleaned up

This commit is contained in:
Janis M
2022-03-09 13:38:39 +01:00
parent 675481d8ad
commit 598cce9611
5 changed files with 107 additions and 58 deletions

View File

@@ -4,43 +4,6 @@ using UnityEngine;
public class Testing : MonoBehaviour {
private Pathfinding pathfinding;
int originX = 0;
int originY = 0;
private void Start() {
pathfinding = new Pathfinding(20, 10);
}
private void Update() {
if (Input.GetMouseButtonDown(0)) {
Vector3 mouseWorldPosition = Camera.main.ScreenToWorldPoint(Input.mousePosition);
pathfinding.GetGrid().GetXY(mouseWorldPosition, out int x, out int y);
List<PathNode> path = pathfinding.FindPath(originX, originY, x, y);
if (path != null) {
float cellSize = pathfinding.GetGrid().GetCellSize();
for (int i=0; i<path.Count - 1; i++) {
Debug.DrawLine(new Vector3(path[i].x, path[i].y) * cellSize + Vector3.one * cellSize/2, new Vector3(path[i+1].x, path[i+1].y) * cellSize + Vector3.one * cellSize/2, Color.green, 5f);
}
}
//characterPathfinding.SetTargetPosition(mouseWorldPosition);
}
if (Input.GetMouseButtonDown(1)) {
Vector3 mouseWorldPosition = Camera.main.ScreenToWorldPoint(Input.mousePosition);
pathfinding.GetGrid().GetXY(mouseWorldPosition, out int x, out int y);
pathfinding.GetNode(x, y).SetIsWalkable(!pathfinding.GetNode(x, y).isWalkable);
originX = x;
originY = y;
}
if (Input.GetMouseButtonDown(2))
{
Vector3 mouseWorldPosition = Camera.main.ScreenToWorldPoint(Input.mousePosition);
pathfinding.GetGrid().GetXY(mouseWorldPosition, out int x, out int y);
pathfinding.GetNode(x, y).SetIsWalkable(!pathfinding.GetNode(x, y).isWalkable);
}
}
}