public void processGaze() { Ray raycastRay = new Ray(transform.position, direction: transform.forward); RaycastHit hitInfo; Debug.DrawRay(raycastRay.origin, raycastRay.direction * 100); if (Physics.Raycast(raycastRay, out hitInfo)) { // do something to the object // get the gameObject from the hitInfo GameObject hitObj = hitInfo.collider.gameObject; // get the gazable object from the hit object gazableObjects gazeObj = hitObj.GetComponent <gazableObjects>(); // to check if an object has a gazableObject if (gazeObj != null) { // to check if the object we are looking at is different from the previous if (gazeObj != currentGazeObject) { clearCurrentObject(); currentGazeObject = gazeObj; currentGazeObject.OnGazeEnter(hitInfo); SetReticleColor(activeReticleColor); } else { currentGazeObject.OnGaze(hitInfo); } } else { clearCurrentObject(); } lastHit = hitInfo; } else { clearCurrentObject(); } }