Play different sounds on different surfaces?

How to play different footstep audio sounds when within triggers or on different surfaces?

Ok so been searching around quite a bit and found some close answers but I cannot get them to work. So starting from the ground up here. I have a script that allows footstep audio sounds to played when walking. Now I need to find a way to add to this code so when my capsule collider is walking on/in different triggers or on different surfaces it plays different sounds. EXAMPLE: Character walking on wood plays footstep sounds that sound like walking on wood and if character walks onto a carpet it plays carpet footstep sounds.

This is as far as I am so far.

var audioStepLength = 0.3;

var walkSounds:AudioClip[];
var footAudioRandomness = 0.1;
var soundEffectPitchRandomness = 0.05;
 
function Start ()

{        var controller : CharacterController = GetComponent(CharacterController);
    while (true)

    {
        if (controller.isGrounded && controller.velocity.magnitude > 0.3)

        {
            audio.clip = walkSounds[Random.Range(0, walkSounds.length)];

            audio.volume = Random.Range(0.4 - footAudioRandomness, 0.4 + footAudioRandomness);
            audio.pitch = Random.Range(1.0 - soundEffectPitchRandomness, 1.0 + soundEffectPitchRandomness);
            audio.Play();
			
            yield WaitForSeconds(audioStepLength);
        }
        else
        {
            yield;
        }
    }
}

Any solid ideas? Any and all help is greatly appreciated.

I will go this way:

  1. Use different tag for different ground surface.
  2. In your coroutine, cast a ray vertically to check the tag of the surface.
  3. Depending on the tag, play a different sound and/or adjust the pitch or other values of some filters.