38 lines
1 KiB
C#
38 lines
1 KiB
C#
using System;
|
|
using TMPro;
|
|
using UnityEngine;
|
|
using UnityEngine.EventSystems;
|
|
|
|
public class AbilityHotbarIcon : MonoBehaviour, IPointerEnterHandler, IPointerExitHandler
|
|
{
|
|
public Transform cooldownBar;
|
|
[SerializeField] private TextMeshProUGUI text;
|
|
private PlayerAbility thisAbility;
|
|
[SerializeField] private FloatingAbilityInfo infoUI;
|
|
|
|
private void Update()
|
|
{
|
|
if (thisAbility.currentCooldown > 0f || cooldownBar.localScale.x < 1f)
|
|
{
|
|
cooldownBar.localScale = new Vector3(Math.Clamp(1f - thisAbility.currentCooldown/thisAbility.cooldown, 0f, 1f), 1f, 1f);
|
|
}
|
|
}
|
|
|
|
public void UpdateAbility(PlayerAbility ability)
|
|
{
|
|
thisAbility = ability;
|
|
ability.thisHotbarIcon = this;
|
|
text.text = thisAbility.abilityName;
|
|
}
|
|
public void OnPointerEnter(PointerEventData eventData)
|
|
{
|
|
infoUI.gameObject.SetActive(true);
|
|
infoUI.ShowInfo(thisAbility);
|
|
|
|
}
|
|
public void OnPointerExit(PointerEventData eventData)
|
|
{
|
|
infoUI.gameObject.SetActive(false);
|
|
|
|
}
|
|
}
|