fgm24/Assets/Scripts/Player/FootStepSounder.cs

25 lines
659 B
C#

using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class FootStepSounder : MonoBehaviour
{
[SerializeField] private float StepInterval = 0.5f;
[SerializeField] private float Volume = 0.25f;
private float movedDist = 0;
private Vector3 prevPos;
// Update is called once per frame
void Update()
{
movedDist += Vector3.Distance(transform.position, prevPos);
if (movedDist % StepInterval < 0.2f)
{
AudioManager.PlaySound("Footstep_" + UnityEngine.Random.Range(1, 6), transform.position).volume = Volume;
}
prevPos = transform.position;
}
}