Skip to content

Instantly share code, notes, and snippets.

@oismaelash
Created May 6, 2020 23:26
Show Gist options
  • Save oismaelash/f2f8e2f7f38f1143cefd9c6d0868ce24 to your computer and use it in GitHub Desktop.
Save oismaelash/f2f8e2f7f38f1143cefd9c6d0868ce24 to your computer and use it in GitHub Desktop.
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