Advertisement
svetliaka92

Tile.cs

Feb 27th, 2020
429
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 1.17 KB | None | 0 0
  1. using System.Collections;
  2. using System.Collections.Generic;
  3. using UnityEngine;
  4.  
  5. public class Tile : MonoBehaviour
  6. {
  7.     [SerializeField] private GameObject _body;
  8.  
  9.     private Renderer _bodyRend;
  10.  
  11.     private Unit _occupant;
  12.     public Unit Occupant => _occupant;
  13.  
  14.     private Grid grid;
  15.     private int x;
  16.     private int y;
  17.  
  18.     public int X => x;
  19.     public int Y => y;
  20.     private bool isWalkable;
  21.     private bool isOccupied;
  22.  
  23.     public int gCost;
  24.     public int hCost;
  25.     public int fCost => gCost + hCost;
  26.  
  27.     public Tile cameFromTile;
  28.  
  29.     private void Awake()
  30.     {
  31.         _bodyRend = _body.GetComponent<Renderer>();
  32.     }
  33.  
  34.     public void SetTileData(Grid grid, int x, int y)
  35.     {
  36.         this.grid = grid;
  37.         this.x = x;
  38.         this.y = y;
  39.     }
  40.  
  41.     public void SetWalkable(bool isWalkable = true)
  42.     {
  43.         this.isWalkable = isWalkable;
  44.     }
  45.  
  46.     public bool IsWalkable() => isWalkable && !isOccupied;
  47.  
  48.     public void SetTileMat(Material mat)
  49.     {
  50.         _bodyRend.material = mat;
  51.     }
  52.  
  53.     public void SetUnitOnTile(Unit unit)
  54.     {
  55.         _occupant = unit;
  56.         isOccupied = _occupant != null;
  57.     }
  58. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement