using System.Collections; using System.Collections.Generic; using TMPro; using UnityEngine; using UnityEngine.Rendering; using UnityEngine.UI; public class GSAbilities : MonoBehaviour { [Header("Ability 1")] public Image abilityImage1; public TextMeshProUGUI abilityText1; public float ability1Cooldown = 5; [Header("Ability 2")] public Image abilityImage2; public TextMeshProUGUI abilityText2; public float ability2Cooldown = 7; [Header("Ability 3")] public Image abilityImage3; public TextMeshProUGUI abilityText3; public float ability3Cooldown = 10; private bool isAbility1Cooldown = false; private bool isAbility2Cooldown = false; private bool isAbility3Cooldown = false; private float currentAbility1Cooldown; private float currentAbility2Cooldown; private float currentAbility3Cooldown; // Start is called before the first frame update void Start() { abilityImage1.fillAmount = 0; abilityImage2.fillAmount = 0; abilityImage3.fillAmount = 0; abilityText1.text = ""; abilityText2.text = ""; abilityText3.text = ""; } // Update is called once per frame void Update() { AbilityCooldown(ref currentAbility1Cooldown, ability1Cooldown, ref isAbility1Cooldown, abilityImage1, abilityText1); AbilityCooldown(ref currentAbility2Cooldown, ability2Cooldown, ref isAbility2Cooldown, abilityImage2, abilityText2); AbilityCooldown(ref currentAbility3Cooldown, ability3Cooldown, ref isAbility3Cooldown, abilityImage3, abilityText3); } public void Ability1() { if(!isAbility1Cooldown) { isAbility1Cooldown = true; currentAbility1Cooldown = ability1Cooldown; } } public void Ability2() { if (!isAbility2Cooldown) { isAbility2Cooldown = true; currentAbility2Cooldown = ability2Cooldown; } } public void Ability3() { if (!isAbility3Cooldown) { isAbility3Cooldown = true; currentAbility3Cooldown = ability3Cooldown; } } private void AbilityCooldown(ref float currentCooldown, float maxCooldown, ref bool isCooldown, Image skillImage, TextMeshProUGUI skillText) { if (isCooldown) { currentCooldown -= Time.deltaTime; if(currentCooldown <= 0f) { isCooldown = false; currentCooldown = 0f; if(skillImage != null) { skillImage.fillAmount = 0f; } if(skillText != null) { skillText.text = ""; } } else { if(skillImage != null) { skillImage.fillAmount = currentCooldown / maxCooldown; } if(skillText != null) { skillText.text = Mathf.Ceil(currentCooldown).ToString(); } } } } }