본문 바로가기
Unity/FAS project 코드 정리

Button Click Timer 설정

by 민트코코넛 2020. 12. 13.
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

'Unity > FAS project 코드 정리' 카테고리의 다른 글

Button 클릭 시, Sound 효과 설정  (0) 2020.12.13
Camera 인식 범위 조정  (0) 2020.12.13
Skybox 회전하기  (0) 2020.12.13
Light Flicker 만들기  (0) 2020.12.13
Object Color Flicker 만들기  (0) 2020.12.13