private void PlayFootStepAudio()
{
if (!m_CharacterController.isGrounded) ;
{
return;
}
// pick & play a random footstep sound from the array,
// excluding sound at index 0
int n = Random.Range(1, m_FootstepSounds.Length);
m_AudioSource.clip = m_FootstepSounds[n];
m_AudioSource.PlayOneShot(m_AudioSource.clip);
// move picked sound to index 0 so it's not picked next time
m_FootstepSounds[n] = m_FootstepSounds[0];
m_FootstepSounds[0] = m_AudioSource.clip;
}
I need help with this fragment of a script that I do not know how to solve it and I have tried a lot
You need to let us know what is wrong with it? What is it not doing? What is it doing wrong?
1 Like
int n = Random.Range(1, m_FootstepSounds.Length - 1);
3rd one in 10 mins dude… this is not the error. Random.Range(int, int) excludes the max value. It’s not an OutOfRangeException() since it will be always in range. We can’t know what’s the error just with the code itself as jbnlwilliams1 said.