더보기
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.UI;
using TMPro;
public class UISkillButton : MonoBehaviour
{
public TMP_Text text;
public Image imgFront;
public bool isCoolDown = false;
public float coolDownTime = 10f;
private float delta;
private float delta2;
public void StartCoolDown()
{
this.delta = 0;
this.delta2 = this.coolDownTime;
this.isCoolDown = true;
this.imgFront.fillAmount = 0;
this.text.text = this.coolDownTime.ToString();
this.text.gameObject.SetActive(true);
StartCoroutine(this.WaitForCoolDown());
}
private IEnumerator WaitForCoolDown()
{
while (true)
{
this.delta += Time.deltaTime;
this.delta2 -= Time.deltaTime;
float fillamount = this.delta / this.coolDownTime;
this.text.text = this.delta2.ToString("F0");
this.imgFront.fillAmount = this.delta / this.coolDownTime;
if (this.delta2 <= 0)
{
break;
}
yield return null;
}
this.StopCoolDown();
}
private void StopCoolDown()
{
this.isCoolDown = false;
this.text.gameObject.SetActive(false);
Debug.Log("CoolDown complete");
}
}
아이템버튼 커스터마이징
더보기
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.UI;
using TMPro;
public class UIBombButton : MonoBehaviour
{
public bool isCoolDown = false;
public TMP_Text text;
public GameObject frontGo;
public float coolDownTime = 10f;
private float delta;
private float delta2;
public GameObject[] frameGos;
void Start()
{
}
public void StartCoolDown()
{
this.delta = 0;
this.delta2 = this.coolDownTime;
this.isCoolDown = true;
this.text.gameObject.SetActive(true);
this.frontGo.SetActive(false);
foreach (var frameGo in frameGos)
{
frameGo.SetActive(false);
}
StartCoroutine(this.WaitForCoolDown());
}
private IEnumerator WaitForCoolDown()
{
while (true)
{
this.delta += Time.deltaTime;
this.delta2 -= Time.deltaTime;
this.text.text = this.delta2.ToString("F0");
if (this.delta / this.coolDownTime >= 1 / 6f-0.07)
{
this.frameGos[0].SetActive(true);
}
if (this.delta / this.coolDownTime >= 1 / 3f-0.07)
{
this.frameGos[1].SetActive(true);
}
if (this.delta / this.coolDownTime >= 1 / 2f-0.07)
{
this.frameGos[2].SetActive(true);
}
if (this.delta / this.coolDownTime >= 2 / 3f-0.07)
{
this.frameGos[3].SetActive(true);
}
if (this.delta / this.coolDownTime >= 5 / 6f-0.07)
{
this.frameGos[4].SetActive(true);
}
if (this.delta / this.coolDownTime >= 0.92f)
{
this.frameGos[5].SetActive(true);
}
if (this.delta2 <= 0.1f)
{
break;
}
yield return null;
}
this.StopCoolDown();
}
private void StopCoolDown()
{
this.isCoolDown = false;
this.text.gameObject.SetActive(false);
this.frontGo.SetActive(true);
Debug.Log("CoolDownComplete");
}
'유니티 > 수업 내용' 카테고리의 다른 글
[UGUI] UIStage (0) | 2022.01.18 |
---|---|
[UGUI] 버젯, InputField (0) | 2022.01.18 |
[UGUI] UI만들기 - Tab (0) | 2022.01.18 |
[UGUI] UI 만들기 (0) | 2022.01.18 |
씬전환하기 (0) | 2022.01.18 |