Animation Scripting Help

I have wrote this script which is supposed to loop an animation when the LMB is held down and when let go stops the animation. But it only plays my animation once, im not sure what ive missed out can someone please help me?

function Start () {


animation["shoot"].speed = 2.5;



 animation.wrapMode = WrapMode.Loop;

 

}



function Update () {



if ( Input.GetButtonDown("Fire1")) {



   transform.animation.Play("shoot");

   

if ( Input.GetButtonUp("Fire1")) {



   transform.animation.Stop("shoot");

   

}   

}

}

It looks like the problem is that you are setting the wrap mode on the animation object rather than the clip's animation state.

The code where you you are setting the wrap mode should be as follows:

animation["shoot"].wrapMode = WrapMode.Loop;

Edit: There is a second, unrelated problem with the code. (It doesn't have an impact on your looping issue.) Here is the correct code to get the behavior you are looking for.

function Start () {

    animation["shoot"].speed = 2.5;
    animation["shoot"].wrapMode = WrapMode.Loop;

}

function Update () {

    if (Input.GetButtonDown("Fire1")) {

       transform.animation.Play("shoot");

    }

    // In the original code you have this inside the button down check,
    // so the button up is never detected.
    if (Input.GetButtonUp("Fire1")) {

       transform.animation.Stop("shoot");  

    }
}