void Update() { if (_blockInteraction) { return; } if (playerEntered) { //center point of viewport in World space. Vector3 rayOrigin = fpsCam.ViewportToWorldPoint(new Vector3(0.5f, 0.5f, 0f)); RaycastHit hit; //if raycast hits a collider on the rayLayerMask if (Physics.Raycast(rayOrigin, fpsCam.transform.forward, out hit, reachRange, rayLayerMask)) { MoveableObject moveableObject = null; //is the object of the collider player is looking at the same as me? if (!isEqualToParent(hit.collider, out moveableObject)) { //it's not so return; return; } if (moveableObject != null && FirstPersonMovement.Instance.CanInteract()) { if (_scriptable != null && !FirstPersonMovement.Instance.HasKey(_scriptable)) { if (Input.GetButtonDown(InputButton.Interact.ToString())) { SfxContoller.Instance?.DoorLocked(transform.position); } return; } _moveableObjectReference = moveableObject; if (_lastMoveableObjectReference != _moveableObjectReference) { _lastMoveableObjectReference?.SetCanInteract(false); } _lastMoveableObjectReference = _moveableObjectReference; string animBoolNameNum = animBoolName + _moveableObjectReference.objectNumber.ToString(); bool isOpen = anim.GetBool(animBoolNameNum); _moveableObjectReference?.SetCanInteract(true); if (Input.GetButtonDown(InputButton.Interact.ToString())) { if (_scriptable != null && FirstPersonMovement.Instance.HasKey(_scriptable)) { _blockInteraction = true; SfxContoller.Instance?.DoorUnlock(transform.position); _moveableObjectReference?.SetCanInteract(false); } anim.enabled = true; anim.SetBool(animBoolNameNum, !isOpen); } } } else { _moveableObjectReference?.SetCanInteract(false); _moveableObjectReference = null; } } else { _moveableObjectReference?.SetCanInteract(false); _moveableObjectReference = null; } }