How to make it so my animation doesn't auto play?

I was just wondering how to go about making it so my animation script will not repeat, but only play once, also adding some sort of a cool down to it. Thank you so much in advance, since I’m not that seasoned with scripting.

using UnityEngine;
using System.Collections;

public class attackAnim : MonoBehaviour
{
	public string AttackButton;
	public float attackSpeed;

	private Animator anim;
	private float attack;
	void Start ()
	{
		anim = gameObject.GetComponent<Animator> ();
	}
	// Update is called once per frame
	void Update ()
	{
		anim.SetFloat ("Attack", attack);
		if(Input.GetKeyDown(AttackButton))
		{
			attack = attackSpeed;
		}
		if(attack > 0f)
		{
			attack -= Time.deltaTime;
		}
	}
}

I don´t have a scripted answer for you cause I´m using Unity Javascript.
Your animation plays all the time because it is inside the update loop, everything in this loop, as long as it isn´t part of a function that changes this, will be constantly updated and executed :wink:
I would recommend that you put the |anim.SetFloat (“Attack”, attack);| part inside the if statement but that depends on what you try to achieve.