Advertisement
Guest User

Untitled

a guest
Dec 12th, 2019
279
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 1.55 KB | None | 0 0
  1.     IEnumerator Moving(Cell[,] grid, List<Spot> path)
  2.     {
  3.         var pathIndex = path.Count - 1;
  4.         while (pathIndex >= 0 && path != null)
  5.         {
  6.             Vector3 goal = grid[path[pathIndex].X, path[pathIndex].Y].gameObject.transform.position;
  7.  
  8.  
  9.             transform.Translate((goal - transform.position) * Time.fixedDeltaTime * 15);
  10.             if (Vector3.Distance(transform.position, goal) < 0.025f)
  11.             {
  12.                 grid[path[pathIndex].X, path[pathIndex].Y].Renderer.color = Color.white;
  13.                 grid[path[pathIndex].X, path[pathIndex].Y].entity = null;
  14.  
  15.                 path.RemoveAt(pathIndex);
  16.  
  17.                 transform.position = goal;
  18.                 pathIndex--;
  19.                 if (pathIndex >= 0)
  20.                 {
  21.                     X = path[pathIndex].X;
  22.                     Y = path[pathIndex].Y;
  23.                     GetComponent<SpriteRenderer>().sortingOrder = Utils.Rows-Y+1;
  24.                     grid[X, Y].entity = this;
  25.                     //if (pathIndex != 0)
  26.                     //{
  27.                     //    var newX = path[0].X;
  28.                     //    var newY = path[0].Y;
  29.                     //    path = GridManager.instance.astar.CreatePath(grid, new Vector2Int(X, Y), new Vector2Int(newX, newY), walkDistance);
  30.                     //}
  31.                 }
  32.             }
  33.             yield return new WaitForFixedUpdate();
  34.         }
  35.         grid[X, Y].entity = this;
  36.         PlaceOnGrid(grid, X, Y);
  37.         TurnActive = false;
  38.         GameManager.instance.OnTurnFinished();
  39.     }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement