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); } } }
private void Footstep() => OnFootstep?.Invoke();