How i can make that detect if the player is grounded and play the footstep audio 1 time? because it is repeating the sound all the time when i am grounded
if (m_CharacterController.isGrounded)
{
FootstepSounds footstep;
footstep = GetComponentInChildren<FootstepSounds>();
footstep.FootStep(); //PLAY THE SOUND
}
Lots of way to do it, like using OnCollisionEnter and checking the tag of the other object, but you can try this:
Declare a variable to store the previous state
private bool wasGrounded = true;
And then just do
if (m_CharacterController.isGrounded && !wasGrounded)
{
GetComponentInChildren<FootstepSounds>().FootStep(); //PLAY THE SOUND
}
wasGrounded = m_CharacterController.isGrounded;