You cannot select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

41 lines
1.5 KiB
C#

2 weeks ago
2 weeks ago
using UnityEngine;
using Sirenix.OdinInspector;
[HideMonoScript]
public class AnimationEventReceiver : MonoBehaviour
{
[Title("ANIMATION EVENT RECEIVER", titleAlignment: TitleAlignments.Centered)]
[SerializeField] bool _playFootStepSounds = true;
// [SerializeField] CharacterController _controller = null;
[SerializeField] Rigidbody _rigidbody = null;
[SerializeField] AudioClip _landingAudioClip = null;
[SerializeField] AudioClip[] _footstepAudioClips;
[Range(0, 1)]
[SerializeField] float _footstepAudioVolume = 0.5f;
private void OnFootstep(AnimationEvent animationEvent)
{
if(_playFootStepSounds is false || _rigidbody == null)
return;
if (animationEvent.animatorClipInfo.weight > 0.5f)
{
if (_footstepAudioClips.Length > 0)
{
int index = Random.Range(0, _footstepAudioClips.Length);
AudioSource.PlayClipAtPoint(_footstepAudioClips[index], transform.TransformPoint(_rigidbody.centerOfMass), _footstepAudioVolume);
}//if end
}//if end
}//OnFootstep() end
private void OnLand(AnimationEvent animationEvent)
{
if(_playFootStepSounds is false || _rigidbody == null)
return;
if (animationEvent.animatorClipInfo.weight > 0.5f)
AudioSource.PlayClipAtPoint(_landingAudioClip, transform.TransformPoint(_rigidbody.centerOfMass), _footstepAudioVolume);
}//OnLand() end
}//class end