-
Notifications
You must be signed in to change notification settings - Fork 0
/
FootStepSFX.cs
30 lines (27 loc) · 898 Bytes
/
FootStepSFX.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.InputSystem.XR;
public class FootStepSFX : MonoBehaviour
{
[Header("SFX")]
public AudioClip LandingAudioClip;
public AudioClip[] FootstepAudioClips;
[Range(0, 1)]
public float FootstepAudioVolume = 0.3f;
public void OnFootstep(AnimationEvent animationEvent)
{
if (animationEvent.animatorClipInfo.weight > 0.5f)
{
if (FootstepAudioClips.Length > 0)
{
var index = Random.Range(0, FootstepAudioClips.Length);
AudioSource.PlayClipAtPoint(FootstepAudioClips[index], transform.position, FootstepAudioVolume);
}
}
}
private void OnLand(AnimationEvent animationEvent)
{
AudioSource.PlayClipAtPoint(LandingAudioClip, transform.position, FootstepAudioVolume);
}
}