Unity/FAS project 코드 정리
Button Click Timer 설정
민트코코넛
2020. 12. 13. 23:04
728x90
반응형
1.
using UnityEngine;
using UnityEngine.EventSystems;
using UnityEngine.UI;
public class ButtonTimer : MonoBehaviour, IPointerEnterHandler, IPointerExitHandler
{
[SerializeField]
float SetTime;
float timeremain;
Button UIButton;
void Start()
{
UIButton = GetComponent<Button>();
timeremain = SetTime;
}
public void OnPointerEnter(PointerEventData eventData)
{
InvokeRepeating("countDown", 0, Time.deltaTime);
}
public void OnPointerExit(PointerEventData eventData)
{
CancelInvoke("countDown");
timeremain = SetTime;
}
void countDown()
{
if (timeremain < 0)
{
UIButton.onClick.Invoke();
CancelInvoke("countDown");
timeremain = SetTime;
}
timeremain-=Time.deltaTime;
}
public void GazeSelect()
{
Debug.Log(gameObject.name + "selected");
}
}
// 같이 프로젝트를 진행한 팀원이 작성한 것으로, 추가 공부 필수
728x90