쿨타임 표시 구현
1. 이미지 UI 준비
2. Image Type 변경
Filed로 변경
3. 보이는 방향 설정
4. 희미한 이미지 준비
5. 코드 작성
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.UI;
public class UIManager : MonoBehaviour
{
[Header("Skill CoolTime Image")]
[SerializeField] private Image _image;
[field: SerializeField] public Player Player { get; private set; }
public void CoolTimeCount()
{
StartCoroutine(CoolTimeRoutine());
}
IEnumerator CoolTimeRoutine()
{
float coolTime = Player.Data.SkillData.SkillCoolTime;
float timer = 0f;
while (true)
{
timer += Time.deltaTime;
float per = timer / coolTime;
_image.fillAmount = per;
if (timer >= coolTime)
{
_image.fillAmount = 1f;
break;
}
yield return null;
}
}
}
UIManger에 작성해서, 스킬을 사용할 때 함수 호출
* 코루틴을 사용하지 않고, 일반 함수에서 위와 같이 while문을 사용하면, 유니티 작동이 멈춤
6. 인스펙터 연결
'유니티' 카테고리의 다른 글
씬 이동 (0) | 2023.12.28 |
---|---|
SoundManger (0) | 2023.12.28 |
이미지 파일 Sprite 변환 (0) | 2023.12.28 |
Terrain (0) | 2023.12.27 |
포톤 (0) | 2023.12.27 |