private void Update() { if (!_isGrabbing) { RaycastHit[] hit = new RaycastHit[1]; if (Physics.RaycastNonAlloc(_pointerRay.position, _pointerRay.forward, hit) > 0) { MediaPlayerButton wb = hit[0].transform.GetComponent <MediaPlayerButton>(); if (wb != null) { if (_lastButtonHit == null) { wb.OnRaycastEnter?.Invoke(hit[0].point); _lastButtonHit = wb; _pointerLight.color = _pointerLightColorHit; } else if (_lastButtonHit == wb) { _lastButtonHit.OnRaycastContinue?.Invoke(hit[0].point); } else { _lastButtonHit.OnRaycastExit?.Invoke(hit[0].point); _lastButtonHit = null; } } else { if (_lastButtonHit != null) { _lastButtonHit.OnRaycastExit?.Invoke(hit[0].point); _lastButtonHit = null; } _pointerLight.color = _pointerLightColorNoHit; } UpdatePointer(hit[0].point); } else { _lastButtonHit = null; ClearPointer(); } } else if (_isGrabbing) { // _isGrabbing already guarantees that _lastButtonHit is not null // but just in case the actual button gets destroyed in // the middle of the grab, let's still check if (_lastButtonHit != null && _lastButtonHit.OnControllerDrag != null) { _lastButtonHit.OnControllerDrag(_controllerConnectionHandler.ConnectedController); } } }