Play sound on animation event?

Ive been trying to add audio to my game and have heard there’s a way of adding sound to animation events, Im not to sure how to script this or how to set an event properly. I have started a script and I have my animations, If someone could point me in the right direction I would be greatfull.

var footsteps : AudioClip;

function Update () {

if(AnimationEvent); //when the animation event happens in animation "gun walk" do something
audio.clip = footsteps;


Try this.

var footsteps : AudioClip;

function footstepsEvent(){

    var footstepsEvent = new AnimationEvent();
    footstepsEvent.functionName = "footstepsSound";        
    footstepsEvent.time = 0.0;

    animation{"gun walk"].layer = 1;
    animation["gun walk"].clip.AddEvent(footstepsEvent); // Add the event to an AnimationClip
    animation["gun walk"].wrapMode = WrapMode.Once;
    animation.Play("gun walk");

function footstepsSound(){

    audio.volume = 1.5;
    audio.clip = footsteps;


This is an old one I used, you could alter it to your requirements … hope it helps you out.

var fireSoundEnd : AudioClip;	// Set end gun sound for the weapon

// Create and set up the Reload AnimationEvent so the var reloadsound will play with the animation
function reload1(){

	var reloadEvent = new AnimationEvent();
		reloadEvent.functionName = "reload2";			// Add the sound below - function reload2();
			reloadEvent.time = 0.0;
		animation["Reload"].layer = 1;					// Place the Reload animation on a higher level so it will take priority and play
		animation["Reload"].clip.AddEvent(reloadEvent); // Add the event to an AnimationClip

    	animation["Reload"].wrapMode = WrapMode.Once;	// Set the animation to play once
		animation.Play("Reload");						// Play the animation

function reload2(){


function reloadGunSound(){

	audio.volume = 0.5;
	audio.loop = false;
	audio.clip = reloadSound;