What's the easiest way of changing footsteps sound depending on floor material?


I know basically nothing about coding and have so far just been taking scripts from various places in order to get my game to work. At the moment I have a script which plays random footstep sounds when I walk, which is fine, but I want to change these when the character is walking on certain materials. I have seen there seems to be several ways of doing this but I am a bit confused as to how I should go about doing it. My theory is that I would just make a box collider and then if the player is walking through it, it will play different sounds to when they aren't. I've got no idea how to do this however. If someone could just point me in the right direction I'm sure I could work it out. Thanks!

I believe the 2D platform tutorial uses triggers and tags

Two ways you could do it include:

1 Like you said, placing a large box collider marked as a trigger and tagged whatever material. Let's say "WoodFloor". Then your character would have a script with :

 function OnTriggerStay (col : Collider) {

     if (!col.tag) return;     

     var floorType : String = col.tag;

     switch(floorType) {
         case "WoodFloor":
                // play wood floor footsteps.
         case "MetalFloor":
              // play metal footsteps
         default: //if the tag is not a floor type

2 Another very similar way would be to tag the floor and use OnControllerColliderHit or OnCollisionEnter to find the tag of the floor and play footsteps accordingly. The code is almost identical to the code above.

A good way is to create a sound with the same name as each material used as ground, then just detect the material's name of the ground under the player, and play the corresponding footstep sound based on its string name.

In Unity 3 you can now use Audio Reverb Zones to easily change the way your footsteps sound.