Advertisement
jwow22

Body movement

Jan 4th, 2022
178
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 0.87 KB | None | 0 0
  1. public class Body : MonoBehaviour
  2. {
  3.     public GridObject gridObject;
  4.     [NonSerialized] public Tile previousTile;
  5.     [NonSerialized] public Snake snake;
  6.     public bool linked;
  7.  
  8.     public void MoveToTile(Tile tile)
  9.     {
  10.         if (!linked) { return; }
  11.         if (tile == null) { return; }
  12.         transform.position = tile.worldPosition;
  13.         Tile temp = gridObject.currentTile;
  14.         previousTile = temp;
  15.         gridObject.currentTile = tile;
  16.        
  17.         UpdateTileProperties();
  18.     }
  19.    
  20.     private void UpdateTileProperties()
  21.     {
  22.         previousTile.walkable = true;
  23.         gridObject.currentTile.walkable = false;
  24.         previousTile.currentObjects.Remove(gridObject);
  25.         gridObject.currentTile.currentObjects.Add(gridObject);
  26.     }
  27.  
  28.     private void Awake()
  29.     {
  30.         gridObject = GetComponent<GridObject>();
  31.     }
  32. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement