void BreakGaze() { if (currentGazeTarget == null) { return; } currentGazeTarget.GazeActive = false; currentGazeTarget.GazeHitPoint = default; currentGazeTarget.GazeJustEntered = false; OnGazeExit?.Invoke(currentGazeTarget); currentGazeTarget = null; }
// Update is called once per frame void Update() { if (ActivationDelay > 0) { ActivationDelay -= Time.deltaTime; return; } Ray ray; #if UNITY_EDITOR ray = Camera.main.ScreenPointToRay(new Vector3(Screen.width / 2, Screen.height / 2, 0)); #else ray = Camera.main.ScreenPointToRay(new Vector3((float)VRSettings.eyeTextureWidth / 2, (float)VRSettings.eyeTextureHeight / 2, 0)); #endif RaycastHit hit; if (Physics.Raycast(ray, out hit)) { if (hit.transform == transform) { //this object is being hit by ray if (!isLookedAt) { Debug.Log(name + "onGazeEnter"); if (OnGazeEnter != null) { OnGazeEnter.Invoke(); } isLookedAt = true; if (reticleFader != null) { StopCoroutine(reticleFader); } reticleFader = GazeCountdown(); StartCoroutine(reticleFader); } else { if (OnGazeStay != null) { OnGazeStay.Invoke(); } } } else { if (isLookedAt) { isLookedAt = false; Debug.Log(name + " onGazeExit"); if (OnGazeExit != null) { OnGazeExit.Invoke(); } if (reticleFader != null) { StopCoroutine(reticleFader); } vrController.UpdateReticle(0); } } } }