fgm24/Assets/Scripts/Player/FootStepSounder.cs

25 lines
659 B
C#
Raw Normal View History

2024-02-04 02:20:08 +01:00
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);
2024-02-04 08:36:45 +01:00
if (movedDist % StepInterval < 0.2f)
2024-02-04 02:20:08 +01:00
{
2024-02-04 08:36:45 +01:00
AudioManager.PlaySound("Footstep_" + UnityEngine.Random.Range(1, 6), transform.position).volume = Volume;
2024-02-04 02:20:08 +01:00
}
prevPos = transform.position;
}
}