Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System.Collections;
- using System.Collections.Generic;
- using UnityEngine;
- public class Tile : MonoBehaviour
- {
- [SerializeField] Tower towerPrefab;
- [SerializeField] bool isPlaceable;
- public bool IsPlaceable { get{return isPlaceable;}}// this is a property, nothing inside gets altered from outside
- // The property is grouped next to the isPlaceable field for neatness.
- GridManager gridManager;
- Vector2Int coordinates = new Vector2Int();
- void Awake()
- {
- gridManager = FindObjectOfType<GridManager>();
- }
- void Start()
- {
- if(gridManager != null)
- {
- coordinates = gridManager.GetCoordinatesFromPosition(transform.position);
- if(!isPlaceable)
- {
- gridManager.BlockNode(coordinates);
- }
- }
- }
- void OnMouseDown() {
- if(isPlaceable)
- {
- bool isPlaced = towerPrefab.CreateTower(towerPrefab, transform.position);
- isPlaceable = !isPlaced;
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement