private void InteractionOver() { Destroy(_closest); //Cleanup _closest = null; _interactableObjects = null; GazeDisconnected.Invoke(); _inputActive = true; }
private void LateUpdate() { //Orient and move the plane which limits the gaze _forwardPlane.SetNormalAndPosition(_transform.forward, _transform.position); //Head aim routine if (_inputActive && _interactableObjects != null && _interactableObjects.Length != 0) { _closest = null; float closestSqrDistance = Mathf.Infinity; for (int i = 0; i < _interactableObjects.Length; i++) { float sqrDistance = (_transform.position - _interactableObjects[i].transform.position).sqrMagnitude; //If closer than the previous AND within gaze range AND on the right side of the plane if (sqrDistance < closestSqrDistance && sqrDistance <= _gazeMaxSqrDistance && _forwardPlane.GetSide(_interactableObjects[i].transform.position)) { _closest = _interactableObjects[i]; closestSqrDistance = sqrDistance; } } //Fire the event for the GameplayManager if (!_wasLookingAtSomething && _closest != null) { selectionMarker.SetActive(true); _isLookingAtSomething = true; GazeConnected.Invoke(); } else if (_wasLookingAtSomething && _closest == null) { selectionMarker.SetActive(false); _isLookingAtSomething = false; GazeDisconnected.Invoke(); } } //Adjust the gaze constraint if (_isLookingAtSomething) { headMultiAim.weight = Mathf.Clamp01(headMultiAim.weight + Time.deltaTime * 5f); gazeVirtualBone.position = _closest.transform.position; //follow the object if it's moving (or if the character is moving) _wasLookingAtSomething = true; } else { headMultiAim.weight = Mathf.Clamp01(headMultiAim.weight - Time.deltaTime * 5f); _wasLookingAtSomething = false; } }