Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- IEnumerator Moving(Cell[,] grid, List<Spot> path)
- {
- var pathIndex = path.Count - 1;
- while (pathIndex >= 0 && path != null)
- {
- Vector3 goal = grid[path[pathIndex].X, path[pathIndex].Y].gameObject.transform.position;
- transform.Translate((goal - transform.position) * Time.fixedDeltaTime * 15);
- if (Vector3.Distance(transform.position, goal) < 0.025f)
- {
- grid[path[pathIndex].X, path[pathIndex].Y].Renderer.color = Color.white;
- grid[path[pathIndex].X, path[pathIndex].Y].entity = null;
- path.RemoveAt(pathIndex);
- transform.position = goal;
- pathIndex--;
- if (pathIndex >= 0)
- {
- X = path[pathIndex].X;
- Y = path[pathIndex].Y;
- GetComponent<SpriteRenderer>().sortingOrder = Utils.Rows-Y+1;
- grid[X, Y].entity = this;
- //if (pathIndex != 0)
- //{
- // var newX = path[0].X;
- // var newY = path[0].Y;
- // path = GridManager.instance.astar.CreatePath(grid, new Vector2Int(X, Y), new Vector2Int(newX, newY), walkDistance);
- //}
- }
- }
- yield return new WaitForFixedUpdate();
- }
- grid[X, Y].entity = this;
- PlaceOnGrid(grid, X, Y);
- TurnActive = false;
- GameManager.instance.OnTurnFinished();
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement