AsteroidGame/Assets/Entities/Handlers/BuildingHandler.cs

46 lines
1.3 KiB
C#

using System.Collections.Generic;
using UnityEngine;
public class BuildingHandler : MonoBehaviour
{
[Header("Assigned on start")] [SerializeField]
ScoreHandler scoreHandler;
[Header("Assigned on start")] [SerializeField]
int buildingSelector = 0;
[Header("Prefabs")] [SerializeField] List<Tower> buildings = new List<Tower>();
// Start is called before the first frame update
void Start()
{
scoreHandler = FindObjectOfType<ScoreHandler>();
}
public void BuildTower(GameObject _tileGO)
{
//Tile _tile = _tileGO.GetComponentInChildren<Tile>();
//Debug.Log($"Placing tower on Tile: {_tileGO.transform.position}");
//Debug.Log($"Placing tower on Node: {_node.coordinates}");
if (scoreHandler.CurrentBalance - buildings[buildingSelector].Cost < 0)
{
print("Insufficient Funds!");
return;
}
else
{
scoreHandler.ModifyWealth(-buildings[buildingSelector].Cost);
Instantiate(buildings[buildingSelector], _tileGO.transform.position, Quaternion.identity, transform);
}
}
public Vector2Int GetVector2(GameObject _o)
{
return new Vector2Int((Mathf.RoundToInt(_o.transform.position.x) / 10),
(Mathf.RoundToInt(_o.transform.position.z / 10)));
}
}