Пример #1
0
        private void OnTriggerStay(Collider other)
        {
            if (Time.time > _lastUseTime + 0.75f)
            {
                return;
            }

            _lastUseTime = 0.0f;
            var closest = head.position;

            HitDetectorUtilities.DetectHit(closest, _hitSoundRange, null);
        }
Пример #2
0
        private void WalkCycle(float delta)
        {
            if (controller.velocity.sqrMagnitude > 0 && input.Movement != Vector2.zero)
            {
                stepCycle += (controller.velocity.magnitude + delta) * Time.fixedDeltaTime;
            }

            if (!(stepCycle > nextStep))
            {
                return;
            }

            nextStep = stepCycle + stepInterval;

            if (controller.isGrounded == false)
            {
                return;
            }

            var random = UnityEngine.Random.Range(1, footstepClips.Count);

            audioSource.clip = footstepClips[random];
            audioSource.PlayOneShot(audioSource.clip);

            footstepClips[random] = footstepClips[0];
            footstepClips[0]      = audioSource.clip;

            var position = transform.position;

            if (wasLeft)
            {
                wasLeft     = false;
                position.x += controller.radius * 0.5f;
            }
            else
            {
                wasLeft     = true;
                position.x -= controller.radius * 0.5f;
            }

            RaycastHit raycastHit;

            if (Physics.Raycast(position, Vector3.down, out raycastHit))
            {
                OnFootstep?.Invoke(raycastHit.point);
                if (Time.time > _lastSoundTime + 2.0f)
                {
                    _lastSoundTime = Time.time;
                    HitDetectorUtilities.DetectHit(raycastHit.point + _forwardOffset * transform.forward, _footstepSoundRange, _footstepSoundSpeed);
                }
            }
        }
Пример #3
0
    public void Update()
    {
        if (!Input.GetMouseButtonDown(0))
        {
            return;
        }

        RaycastHit hit;
        Ray        ray = _camera.ScreenPointToRay(Input.mousePosition);

        if (Physics.Raycast(ray, out hit))
        {
            HitDetectorUtilities.DetectHit(hit.point, _range, null);
        }
    }