Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- public Vector2Int GetNextTileIndex(Vector2Int currentIndex, Vector2Int movementDirection, bool overwriteMovable = false) {
- Vector2Int newIndex = currentIndex;
- if (currentIndex.x <= TileOwner.GridSize.x - 1 && currentIndex.x + movementDirection.x > TileOwner.GridSize.x - 1) {
- newIndex = new Vector2Int(0, currentIndex.y);
- }
- else if (currentIndex.x >= 0 && currentIndex.x + movementDirection.x < 0) {
- newIndex = new Vector2Int(TileOwner.GridSize.x - 1, currentIndex.y);
- }
- else if (currentIndex.y <= TileOwner.GridSize.y - 1 && currentIndex.y + movementDirection.y > TileOwner.GridSize.y - 1) {
- newIndex = new Vector2Int(currentIndex.x, 0);
- }
- else if (currentIndex.y >= 0 && currentIndex.y + movementDirection.y < 0) {
- newIndex = new Vector2Int(currentIndex.x, TileOwner.GridSize.y - 1);
- }
- else {
- newIndex += movementDirection;
- }
- if (overwriteMovable == true) {
- return newIndex;
- }
- if (TileOwner.GetTileAtIndex(newIndex) != null) {
- if (TileOwner.GetTileAtIndex(newIndex).IsMovableTile() == false) {
- return GetNextTileIndex(newIndex, movementDirection);
- }
- }
- return newIndex;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement