Audio for movement

Hello

I have found this script for giving my 2d character sound for when it walks, although it does not have any legs it moves on a ball. I was wanting sound for just when you press the D or A keys, also if there is a way to add a jumping sound for when you press SPACE bar that would be cool as well. Also if anyone knows what I need to add for when the player gets hit that would also be sweet.

Here's the javascript

var audioStepLength = 0.3;
var walkSounds:AudioClip[];

function Start ()
{
   var controller : CharacterController = GetComponent(CharacterController);

   while (true)
   {

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

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

         audio.Play();

         yield WaitForSeconds(audioStepLength);

      }
      else
      {
         yield;
      }
   }
} 

Thanks

Without stealing your learning:

Check out the 2D Gameplay Tutorial. It basically explains all you need to know when working with 2D platform games in Unity.

Here's a hint for you:

Left/Right is the horizontal axis when working with Input.GetAxis. These are also mapped to A/D, but that depends on the settings in Edit : Project Settings : Input.

You might also want to check out how the character controller works.

Cheers.