Sound Script Error

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

    public void WalkOnConcrete ()
    {
        audio.clip = concreteSound; //[Random.Range(0, concreteSound.Length];
            audio.volume = 1f;
            audio.Play();
            StartCoroutine(WaitForFootSteps(audioStepLengthWalk));
            Debug.Log("audio play");
    }
   
}

You forgot the last parenthesis inside the array.

audio.clip= concreteSound[Random.Range(0, concreteSound.Length)];

“Length” cause an error I don’t know why. I wrote about at the start of my post.

2249634--150296--123.png

Okay, try casting it to an int, Random.Range returns a float. Array indexes are ints.

audio.clip = concreteSound[(int)Random.Range(0, concreteSound.Length)];

Try that Post results if you get an error.

Just tryed still does not contain a definition to a Length, same error.

If you interest I used as a reference for this Script script from this question, its in the end of a question at a firs page : http://answers.unity3d.com/questions/11486/footstep-sounds-when-walking.html

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.

I try to play walk sound when walking. like one sound on a one step of a char controller.

If you stell interested I can achieve sond playng right on different surface, but with JS what I just copy.

Still don’t know why C# script doesn’t work properly this two scripts are prety simmilar.

One day when I learn code greater then I know it now I will translate it to C# but dor now I can achive only JS working version.

var stepWood:AudioClip[];
var stepMetal:AudioClip[]; // fill this array with the sounds at the Inspector
var stepConcrete:AudioClip[];
var footSource1 : AudioSource;
var footSource2 : AudioSource;
var delayBeforeSteps : float = 0.20;
var delayBetweenSteps: float = 0.45;
var audioStepLength : float = 0.60;
var groundType : int;
var isPlayerWalking : float = 0.0;
var footAudioRandomness = 0.1;
var soundEffectPitchRandomness = 0.05;
function Update(){
    //Check to see if the player is walking by checking for input from the walking keys
    if(Input.GetButton("Horizontal") || Input.GetButton("Vertical")){
        //if those keys are pressed, the player must be walking...
        isPlayerWalking += Time.deltaTime;
    }
    else{
        //if those keys aren't pressed, the player can't be walking.....
        isPlayerWalking = 0;
    }
}
function Start(){
    var aSources = GetComponents(AudioSource);
    footSource1 = aSources[0];
    footSource2 = aSources[1];
    while(true){
        if (isPlayerWalking >= 0.20 && groundType == 1){
            yield WaitForSeconds(delayBeforeSteps);
            footSource1.clip = stepMetal[Random.Range(0, stepMetal.length)];
            footSource1.volume = Random.Range(0.4 - footAudioRandomness, 0.4 + footAudioRandomness);
            footSource1.pitch = Random.Range(1.0 - soundEffectPitchRandomness, 1.0 + soundEffectPitchRandomness);
            footSource1.Play();
            if(isPlayerWalking == 0){
                yield;}
            else{
                yield WaitForSeconds(delayBetweenSteps);
                footSource2.clip = stepMetal[Random.Range(0, stepMetal.length)];
                footSource2.volume = Random.Range(0.4 - footAudioRandomness, 0.4 + footAudioRandomness);
                footSource2.pitch = Random.Range(1.0 - soundEffectPitchRandomness, 1.0 + soundEffectPitchRandomness);
                footSource2.Play();
                yield WaitForSeconds(audioStepLength);
                if(isPlayerWalking == 0){
                    yield;}
            }
            
        }
        else if ( isPlayerWalking >= 0.20 && groundType == 2){
            yield WaitForSeconds(delayBeforeSteps);
            footSource1.clip = stepWood[Random.Range(0, stepWood.length)];
            footSource1.volume = Random.Range(0.4 - footAudioRandomness, 0.4 + footAudioRandomness);
            footSource1.pitch = Random.Range(1.0 - soundEffectPitchRandomness, 1.0 + soundEffectPitchRandomness);
            footSource1.Play();
            if(isPlayerWalking == 0){
                yield;}
            else{
                yield WaitForSeconds(delayBetweenSteps);
                footSource2.clip = stepWood[Random.Range(0, stepWood.length)];
                footSource2.volume = Random.Range(0.4 - footAudioRandomness, 0.4 + footAudioRandomness);
                footSource2.pitch = Random.Range(1.0 - soundEffectPitchRandomness, 1.0 + soundEffectPitchRandomness);
                footSource2.Play();
                yield WaitForSeconds(audioStepLength);
                if(isPlayerWalking == 0){
                    yield;}
            }
        }
        else if ( isPlayerWalking >= 0.20 && groundType == 3){
            yield WaitForSeconds(delayBeforeSteps);
            footSource1.clip = stepConcrete[Random.Range(0, stepConcrete.length)];
            footSource1.volume = Random.Range(0.4 - footAudioRandomness, 0.4 + footAudioRandomness);
            footSource1.pitch = Random.Range(1.0 - soundEffectPitchRandomness, 1.0 + soundEffectPitchRandomness);
            footSource1.Play();
            if(isPlayerWalking == 0){
                yield;}
            else{
                yield WaitForSeconds(delayBetweenSteps);
                footSource2.clip = stepConcrete[Random.Range(0, stepConcrete.length)];
                footSource2.volume = Random.Range(0.4 - footAudioRandomness, 0.4 + footAudioRandomness);
                footSource2.pitch = Random.Range(1.0 - soundEffectPitchRandomness, 1.0 + soundEffectPitchRandomness);
                footSource2.Play();
                yield WaitForSeconds(audioStepLength);
                if(isPlayerWalking == 0){
                    yield;}
            }
        }
   
        else{
            yield;
        }
    }
}
function OnControllerColliderHit (hit : ControllerColliderHit){
    if (hit.gameObject.tag == "metalFloor"){
        groundType = 1;
        print("Metal");
    }
    else if (hit.gameObject.tag == "woodFloor"){
        groundType = 2;
        print("Wood");
    }
    else if (hit.gameObject.tag == "Untagged"){
        groundType = 3;
        print("Concrete");
    }
}