Animation on Button Press

Hello Guys,
I need a script so that when I press a button the animation will run
But in my script I need to hold the button to complete the animation

function Update()
{
      if(Input.GetMouseButton(0))
 {
  animation.Play("attack", PlayMode.StopAll);
 }
}

You need to look at the Unity Scripting Reference :