Untitled

 avatar
unknown
csharp
a year ago
790 B
5
Indexable
using System.Collections;
using System.Collections.Generic;
using UnityEngine;

public class Footstep_Sound : MonoBehaviour
{
    [Tooltip("How far gameObject must move until we make sound")]
    [SerializeField] private float stepDistance = 0.6f;

    private Vector3 anchorPosition;
    private Vector3 currentPosition;

    private void Start()
    {
        anchorPosition = transform.position;
    }

    private void Update()
    {
        currentPosition = transform.position;

        Calculate();
    }

    void Calculate()
    {
      float distance = Vector3.Distance(anchorPosition, currentPosition);

        if(distance > stepDistance)
        {
            Debug.Log("Step!");
            anchorPosition = currentPosition;
        }
    }
}
Editor is loading...
Leave a Comment