Loop animation on button hold

how would I change this script so that if the LMB is held down it loops the animation until it has stopped being held but if pressed once it plays the animation once?

function Update () {

if(Input.GetButtonDown(“Fire1”)){

animation.Play(“shoot”);

}

}

You could change the WrapMode depending on the LBM being pressed.

Something in the vicinity of:

function Update()

{

if (Input.GetButtonDown(“Fire1”))

{

if (!animation.isPlaying)

{

animation.Play(“shoot”);

}

}

animation[“shoot”].wrapMode = Input.GetButton(“Fire1”) ? WrapMode.Loop : WrapMode.Once;

}

This will cause the animation to loop if the button is being held, and to stop looping when the button is not being held. Keep in mind when you release the mouse button, animation will not immediately stop, it will rather reach to the end and then stop.

Alternatively, there’s a simpler approach.

function Update () {

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

myanimationisplaying = true;  //boolean value. declare it to false

}

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

myanimationisplaying = false;

}

if (myanimationsiplaying == true)
  animation.Play("shoot");
}
//the rest of the code

Which is how you usually logically implement this kind of functionality.