Make footstep script

Hi! There is a scene in my game that have water., and i wanted to make a script that add (or play) footstep sounds when my character walks in the water. Can someone help me? I have been trying to do this about a week for now and i didn’t get any result.

I wanted to make something like this:

The player is walking normaly in the map, making it’s default footstep sounds (it is a First Person Character). Then he enters in the water. EVERY TIME he walk, a sound is played. There are two different sounds, one for each foot.

The problem is that i don’t know how to make the sound repeat or something, and i don’t know how to get two sounds to play at the same time =
I am using JavaScript, but i would accept C# too.

Here’s my script:

#pragma strict


function OnTriggerEnter (o:Collider) {

    //Below is the code to play the Audio Source attached to the Game Object (the water)
    
        GetComponent.<AudioSource>().Play();
    }

    // The OnTriggerExit function is kinda disabled because i don't need to add anything on it.

    function OnTriggerExit (o:Collider) {
        
    }

This is a very simple Java-Script that play a sound attached to an audio source when the player hit the object’s collider. In my case, the object with this script will be the water. Can someone help me? I don’t have any idea to how to make this…

Hopefully this helps :smiley:

First, your game object can have multiple audio sources, your script should have a public AudioSource variable naming each sound (waterWalk, groundWalk, jumpLanding, etc). Second, you should do this with animation clip events. You can set up a trigger on them to run a method at specific points in the animation clip (let’s call this method OnStep()). That script must be on the same game object as the animator controller. This script will need to know what type of terrain the player is on, this would likely be done through OnCollisionEnter then check the tag of the other collision (ground, water, etc). Then depending on that the just call waterWalk.Play() in the OnStep method.