Created
November 27, 2022 08:29
-
-
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.
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.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