How to play animation with one click

I’m trying to make a lightsaber game and it’s looking pretty good but I’ve run into a problem. When I play the animation for my lightsaber attack (called “Attack” and “Attack2”) it won’t play the animation unless i hold down the mouse button. I want it to be to where i can click once and it plays the animation. I thinks the problem is i have a part in the script where it says if no button is being pushed, play the idle animation. How do I fix this problem?
Here’s my script:

var Rnd : int;
var anim : Animator;

function Update ()
{
         if (Input.GetKeyDown(KeyCode.W)) 
         {
         anim.Play("Walk");
         }
         if (Input.GetKeyDown(KeyCode.A)) 
         {
         anim.Play("Walk");
         }
         if (Input.GetKeyDown(KeyCode.S)) 
         {
         anim.Play("Walk");
         }
         if (Input.GetKeyDown(KeyCode.D)) 
         {
         anim.Play("Walk");
         }

         if (Input.GetButtonDown ("Fire1"))
         {
         	Attack();
         }

          
      if (Input.anyKey == false)
     {
     anim.Play("Idle");
     }
}

function Start()
{
	InvokeRepeating("Randomize",0,1);
}

function Randomize()
{
	Rnd = Random.RandomRange(0,10);
}

function Attack()
{
	if(Rnd < 5)
	{
		anim.Play("Attack");
	}
	else
	{
		anim.Play("Attack2");
	}
}

Thanks in advance!

I think you have to check the state of your animator before calling the idle clip :

if (!anim.GetCurrentAnimatorStateInfo(0).IsName("Attack") && !anim.GetCurrentAnimatorStateInfo(0).IsName("Attack2"))
{
    anim.Play("Idle");
}

Else, if you use the animator state machine, I think you can make a transition between your attacks animation clips to the Idle animation. Thus, you won’t have to deal with it by scripting (same for walking)