Advertisement
Guest User

Untitled

a guest
Jun 21st, 2018
63
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.14 KB | None | 0 0
  1. public Vector2Int GetNextTileIndex(Vector2Int currentIndex, Vector2Int movementDirection, bool overwriteMovable = false) {
  2. Vector2Int newIndex = currentIndex;
  3.  
  4. if (currentIndex.x <= TileOwner.GridSize.x - 1 && currentIndex.x + movementDirection.x > TileOwner.GridSize.x - 1) {
  5. newIndex = new Vector2Int(0, currentIndex.y);
  6. }
  7. else if (currentIndex.x >= 0 && currentIndex.x + movementDirection.x < 0) {
  8. newIndex = new Vector2Int(TileOwner.GridSize.x - 1, currentIndex.y);
  9. }
  10. else if (currentIndex.y <= TileOwner.GridSize.y - 1 && currentIndex.y + movementDirection.y > TileOwner.GridSize.y - 1) {
  11. newIndex = new Vector2Int(currentIndex.x, 0);
  12. }
  13. else if (currentIndex.y >= 0 && currentIndex.y + movementDirection.y < 0) {
  14. newIndex = new Vector2Int(currentIndex.x, TileOwner.GridSize.y - 1);
  15. }
  16. else {
  17. newIndex += movementDirection;
  18. }
  19.  
  20. if (overwriteMovable == true) {
  21. return newIndex;
  22. }
  23.  
  24. if (TileOwner.GetTileAtIndex(newIndex) != null) {
  25. if (TileOwner.GetTileAtIndex(newIndex).IsMovableTile() == false) {
  26. return GetNextTileIndex(newIndex, movementDirection);
  27. }
  28. }
  29.  
  30. return newIndex;
  31. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement