LunarInfantry/Assets/Scripts/ActionUIHandler.cs
2026-01-10 02:37:44 -08:00

69 lines
1.5 KiB
C#

using UnityEngine;
using UnityEngine.UI;
public class ActionUIHandler : MonoBehaviour
{
#region Statication
public static ActionUIHandler instance;
private void Awake()
{
if (instance != null && instance != this)
{
Destroy(gameObject);
return;
}
instance = this;
}
#endregion
private PlayerEntity selectedEntity;
private RangedWeapon possibleRanged;
[Header("UI")]
[SerializeField] private Vector3 offset;
[SerializeField] private GameObject actionUI;
[SerializeField] private Button attackButton;
[SerializeField] private Button reloadButton;
public void ShowUI(PlayerEntity target)
{
possibleRanged = null;
selectedEntity = target;
transform.position = Input.mousePosition + offset;
if (target.currentWeapon.TryGetComponent(out RangedWeapon isRanged))
{
possibleRanged = isRanged;
reloadButton.gameObject.SetActive(true);
}
else
{
reloadButton.gameObject.SetActive(false);
}
actionUI.SetActive(true);
}
public void HideUI()
{
actionUI.SetActive(false);
}
public void ReloadGun()
{
possibleRanged.Reload();
}
public void Attack()
{
selectedEntity.Attack();
}
public void SkipTurn()
{
selectedEntity.SkipTurn();
}
public void MoveEntity()
{
HideUI();
PlayerEntityMovement.instance.SelectEntity(selectedEntity);
}
}