// when we look away form the game object. when not guessing private void clearCurrentObject() { if (currentGazeObject != null) { currentGazeObject.OnGazeExit(); SetReticleColor(inactiveReticleColor); // tell the system we are no longer looking at the game object currentGazeObject = null; } }
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(); } }
private void checkForInput(RaycastHit hitInfo) { if (Input.GetMouseButtonDown(0) && currentGazeObject != null) { // set currently selected object to current gaze object currentSelectedObject = currentGazeObject; // call the onPress method from gazableObjects script acting as a type currentSelectedObject.OnPress(hitInfo); } // to check for hold else if (Input.GetMouseButton(0) && currentGazeObject != null) { currentSelectedObject.OnHold(hitInfo); } // to check for release else if (Input.GetMouseButtonUp(0) && currentGazeObject != null) { currentSelectedObject.OnRelease(hitInfo); currentSelectedObject = null; } }