Created
May 6, 2020 23:26
-
-
Save oismaelash/f2f8e2f7f38f1143cefd9c6d0868ce24 to your computer and use it in GitHub Desktop.
This file contains 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 UnityEngine; | |
using UnityEngine.EventSystems; | |
namespace IsmaelNascimentoAssets | |
{ | |
public class GazeInteraction : MonoBehaviour | |
{ | |
#region VARIABLES | |
[SerializeField] private Material imageChange; | |
[SerializeField] private Renderer cube; | |
[SerializeField] private float gazeTime = .5f; | |
private float timer; | |
private bool gazedAt; | |
#endregion | |
#region MONOBEHAVIOUR_METHODS | |
private void Update() | |
{ | |
if (gazedAt) | |
{ | |
timer += Time.deltaTime; | |
if (timer >= gazeTime) | |
{ | |
ExecuteEvents.Execute(gameObject, new PointerEventData(EventSystem.current), ExecuteEvents.pointerDownHandler); | |
timer = 0f; | |
} | |
} | |
} | |
#endregion | |
#region EVENT_METHODS | |
public void PointerEnter() | |
{ | |
gazedAt = true; | |
Debug.Log("PointerEnter"); | |
} | |
public void PointerExit() | |
{ | |
gazedAt = false; | |
timer = 0; | |
Debug.Log("PointerExit"); | |
} | |
public void PointerDown() | |
{ | |
PointerExit(); | |
cube.material = imageChange; | |
Debug.Log("PointerDown"); | |
} | |
#endregion | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment