Last active
May 20, 2017 11:24
-
-
Save 0V/d8aaf2bd9881af1e2bb48a9a1ed6bb74 to your computer and use it in GitHub Desktop.
Unity(uGUI)で N 回クリックするとオブジェクトをアクティブにするスクリプト
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
using System; | |
using UnityEngine; | |
using UnityEngine.Events; | |
using UnityEngine.EventSystems; | |
public class SecretClickHandler : MonoBehaviour, IPointerClickHandler | |
{ | |
[SerializeField] | |
private ClickEvent clickHandler; | |
[SerializeField] | |
private GameObject secretObject; | |
[SerializeField] | |
private int activeCount = 10; | |
[SerializeField] | |
private float clickInterval = 0.75f; | |
private float lastTimeClick; | |
private int clickCount = 0; | |
public void OnPointerClick(PointerEventData eventData) | |
{ | |
clickCount++; | |
float currentTimeClick = eventData.clickTime; | |
if (Mathf.Abs(currentTimeClick - lastTimeClick) >= clickInterval) | |
{ | |
clickCount = 1; | |
} | |
lastTimeClick = currentTimeClick; | |
// 10回連続クリック | |
if (clickCount >= activeCount) | |
{ | |
// ここにしたい処理を書く | |
secretObject.SetActive(true); | |
} | |
} | |
public void AddClickHandler(UnityAction<GameObject> handler) | |
{ | |
this.clickHandler.AddListener(handler); | |
} | |
[Serializable] | |
public class ClickEvent : UnityEvent<GameObject> { } | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment