コード例 #1
0
ファイル: AbilityBehaviour.cs プロジェクト: lemdoublev/RPG
        protected IEnumerator StartUICooldown(int abilityIndex, float time)
        {
            SpecialAbilities specialAbilities = GetComponent <SpecialAbilities>();

            Image[] cooldownImages  = specialAbilities.GetCooldownImageAbilities();
            Text[]  cooldownNumbers = specialAbilities.GetCooldownNumbers();

            cooldownImages[abilityIndex].fillAmount = 1;
            float fillAmount = 0;

            while (cooldownImages[abilityIndex].fillAmount >= 0)
            {
                if (canCastAbility)
                {
                    cooldownNumbers[abilityIndex].gameObject.SetActive(false);
                    cooldownImages[abilityIndex].fillAmount = 0;
                    yield break;
                }
                float currentTime           = Time.time;
                float remainingCooldownTime = config.GetCoolDown() - (currentTime - time);
                fillAmount = (remainingCooldownTime) / config.GetCoolDown();
                cooldownNumbers[abilityIndex].gameObject.SetActive(true);
                cooldownNumbers[abilityIndex].text      = ((int)remainingCooldownTime + 1).ToString();
                cooldownImages[abilityIndex].fillAmount = fillAmount;
                yield return(new WaitForEndOfFrame());
            }
        }