Skip to content

Instantly share code, notes, and snippets.

@Thilak-KN
Created November 27, 2022 08:29
Show Gist options
  • Select an option

  • Save Thilak-KN/892e4cb6b9c168ba576343993a09a1c3 to your computer and use it in GitHub Desktop.

Select an option

Save Thilak-KN/892e4cb6b9c168ba576343993a09a1c3 to your computer and use it in GitHub Desktop.
Attach this Script to a GameObject. One can add custom behavior instead of Destroying that GameObject.
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class GazeScript : MonoBehaviour
{
bool gazeState = false;
[SerializeField]
float maxTime = 4.0f; //Set the Maximum Timer
float timer = 0f;
// Update is called once per frame
void Update()
{
if(gazeState)
{
Debug.Log(timer); //comment this line if you don't want to Log the Timer value on Debug Console
if(timer >= maxTime)
{
Destroy(gameObject); //Do the stuff you need, I just make this GameObject Destroy
}
timer += Time.deltaTime;
}
}
private void OnMouseEnter()
{
gazeState = true;
timer = 0;
}
private void OnMouseExit()
{
gazeState = false;
timer = 0;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment