gather-and-defend/Assets/Scripts/Drag&Drop/UnitPlacementButton.cs
2024-01-19 15:30:54 -05:00

47 lines
1.1 KiB
C#

using TMPro;
using UnityEngine;
using UnityEngine.EventSystems;
using UnityEngine.UI;
public abstract class UnitPlacementButton : PlacementButton
{
[SerializeField]
protected Sprite _detectionRangeSprite;
[SerializeField]
protected int _wood;
[SerializeField]
protected int _rock;
[SerializeField]
protected int _food;
[SerializeField]
private TMP_Text _foodLabel;
[SerializeField]
private TMP_Text _woodLabel;
[SerializeField]
private TMP_Text _rockLabel;
protected override void Update()
{
base.Update();
SetTextFor(_foodLabel, _food);
SetTextFor(_rockLabel, _rock);
SetTextFor(_woodLabel, _wood);
}
void SetTextFor(TMP_Text label, int value)
{
label.transform.parent.gameObject.SetActive(value > 0);
label.text = "" + value;
}
public override void OnPointerDown(PointerEventData eventData)
{
base.OnPointerDown(eventData);
(Placeholder as UnitPlaceholder).Rock = _rock;
(Placeholder as UnitPlaceholder).Wood = _wood;
(Placeholder as UnitPlaceholder).Food = _food;
}
}