Hello to everyone I take script from this question: Footstep sounds when walking - Questions & Answers - Unity Discussions and modify it a little but in the part of Script audio.clip = concreteSound[Random.Range(0, concreteSound.Lenght)]; the “Length” make an Error does not contain a definition. Can some one please help me to fix it.
Here is the full Script:
public class footStepSoundControll : MonoBehaviour {
public CharacterController controller;
public AudioClip concreteSound;
private bool step = true;
float audioStepLengthWalk = 1f;
// Use this for initialization
void Start () {
controller = GetComponent<CharacterController>();
}
void OnControllerColliderHit (ControllerColliderHit hit)
{
//Debug.Log("Controller hit the ground");
if (controller.isGrounded && controller.velocity.magnitude < 7 && controller.velocity.magnitude > 5 && hit.gameObject.tag == "Untagged" && step == true )
{
WalkOnConcrete();
}
}
IEnumerator WaitForFootSteps(float stepsLength)
{
step = false;
yield return new WaitForSeconds(stepsLength);
step = true;
}
public void WalkOnConcrete ()
{
audio.clip = concreteSound[Random.Range(0, concreteSound.Length];
audio.volume = 1f;
audio.Play();
StartCoroutine(WaitForFootSteps(audioStepLengthWalk));
Debug.Log("audio play");
}
}
Alsow if use script like this it plays sound but only onese when button is pressed, and ones when button is Up
In regards to audio clips, length is spelled with a lowercase L.
Also, if you are trying to get a random clip to be selected from an array of audio clips, make sure that your AudioClips variable is actually an array.
public AudioClip[] concreteSound;
And there needs to be indexes in the array for the script to call. At the moment, there is nothing in the array.
I’m not completely sure what you’re wanting to do. Are you trying to play just a single sound? Or grab from a collection of random Concrete sounds?
Also, if you are trying to get a random clip to be selected from an array of audio clips, make sure that your AudioClips variable is actually an array.
public AudioClip[] concreteSound;
And there needs to be indexes in the array for the script to call. At the moment, there is nothing in the array.
I’m not completely sure what you’re wanting to do. Are you trying to play just a single sound? Or grab from a collection of random Concrete sounds?[/QUOTE]
Yeah just found it, fixed the error, but when walking sound still play only once when start walking, and once when stop walking.