The animation in the Animator is HumanoidWalk In the inspector of the animation in the Animation tab at the bottom I clicked on the Events clicked to add event names the function as Step and moved the time slider to 0.67 moved the slider in the preview window of the character so the right leg foot will be close to the ground and clicked on apply:
Then I did the same but changed the time a bit more almost to 0.7 and called the function Step again and at the preview window now it';s the other leg foot close to the ground and clicked apply:
I added to the character in the hierarchy a Audio Source component and a script name Foot Steps:
And the script it self:
using System;
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class FootSteps : MonoBehaviour
{
[SerializeField]
private AudioClip[] clips;
private AudioSource audioSource;
private GameObject[] Foots;
private void Awake()
{
audioSource = GetComponent<AudioSource>();
Foots = GameObject.FindGameObjectsWithTag("Foot");
}
private void Step()
{
AudioClip clip = GetRandomClip();
audioSource.PlayOneShot(clip);
}
private AudioClip GetRandomClip()
{
return clips[UnityEngine.Random.Range(0, clips.Length)];
}
}
In the Hierarchy in the script in Clips I added same 8 audio clips just for the testing I could add only 1 it doesn't matter:
When running the game I marked with blue circle only this foot play the step/s sounds. And if I change the time to be the same 0.67 it will play two sound the same so it will sound like one or if the time is 0.67 and 0.7 it will hear two steps but only on the left leg foot.
The second leg foot never play the sound no matter how many times I changed the preview animation legs.
I tried to follow the instructions of this tutorial but no success:
Should be simple but only one foot is working. I can't figure out what am I missing.