コード例 #1
0
        private void CheckForInteractable()
        {
            Ray        _ray = new Ray(playerController.mainCamera.transform.position, playerController.mainCamera.transform.forward);
            RaycastHit _hitInfo;

            bool _isHit = Physics.SphereCast(_ray, raySphareRadius, out _hitInfo, rayDistance);

            if (_isHit)
            {
                InteractableBase _interactable = _hitInfo.transform.GetComponent <InteractableBase>();

                if (_interactable)
                {
                    if (_interactable.isInteractable)
                    {
                        if (isNormalText)
                        {
                            SetNormalText(_interactable);
                        }
                        else if (isProText)
                        {
                            SetProText(_interactable);
                        }

                        if (_interactable.holdInteract)
                        {
                            if (InteractClicked())
                            {
                                playerController.blockMovment = true;

                                timer += Time.deltaTime;

                                float _holdPercent = timer / _interactable.holdDuration;
                                if (isProgressBar)
                                {
                                    UpdateProgressBar(_holdPercent);
                                }

                                if (timer >= _interactable.holdDuration)
                                {
                                    _interactable.OnInteract();

                                    playerController.blockMovment = false;

                                    timer = 0;
                                    ResetProgressBar();
                                }
                            }
                            if (InteractRelase())
                            {
                                playerController.blockMovment = false;

                                timer = 0;
                                ResetProgressBar();
                            }
                        }
                        else
                        {
                            if (InteractClick())
                            {
                                _interactable.OnInteract();
                            }
                        }
                    }
                    else
                    {
                        ResetText();
                    }
                }
                else
                {
                    ResetText();
                }
            }
            else
            {
                ResetText();
            }
        }