반응형
- 코드 작성
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.UI;
public class SkillManager : MonoBehaviour
{
[Range(0, 20)]
public float skillTime = 10.0f;
[Range(0, 20)]
public float skillCoolTime = 10.0f;
public Image skillFillAmount;
public Text skillCoolTimeText;
bool isUseSkill = true;
private void Awake()
{
skillInformationText.text = "Skill OFF";
skillCoolTimeText.text = "Skill";
}
public void UseSkill() //스킬 사용
{
if (isUseSkill)
{
isUseSkill = false;
skillCoolTimeText.text = "";
skillFillAmount.fillAmount = 1;
StartCoroutine(SkillCoroutine());
}
}
IEnumerator SkillCoroutine() //스킬 사용중
{
while (skillFillAmount.fillAmount > 0)
{
skillFillAmount.fillAmount -= 1 * Time.smoothDeltaTime / skillTime;
yield return null;
}
StartCoroutine(ResetSkillCoroutine());
StartCoroutine(CoolTimeCountCoroutine(skillCoolTime));
}
IEnumerator ResetSkillCoroutine() //스킬 쿨타임
{
while (skillFillAmount.fillAmount < 1)
{
skillFillAmount.fillAmount += 1 * Time.smoothDeltaTime / skillCoolTime;
yield return null;
}
isUseSkill = true;
}
IEnumerator CoolTimeCountCoroutine(float number) //스킬 쿨타임 텍스트 표시
{
if (number > 0)
{
number -= 1;
skillCoolTimeText.text = number.ToString();
yield return new WaitForSeconds(1f);
StartCoroutine(CoolTimeCountCoroutine(number));
}
else
{
skillCoolTimeText.text = "Skill";
skillFillAmount.fillAmount = 0;
yield break;
}
}
}
참고할만한 글
반응형