Animation Event calling function

I am currently trying to call my function which uses raycast to damage my enemies. Calling Buttondown(); through an animation event mid swing through my sword so you cant spam fire1 and instantly kill the enemy. But now the animation event doesn’t damage the enemy or debug log “hit”. Any help would be apprecaited

The code worked before I decided to add the animation event and button down function so i’m not sure what the problem is, maybe i am calling the function incorrectly.

EDIT: Error message: 'Sword; AnimationEvent ‘ButtonDown’ has no receiver! Are you missing a component?

#pragma strict

var TheDamage : int = 50;
var Distance : float;
var MaxDistance : float = 1.5;
var TheSword : Transform;

//var TheSystem : Transform;

function Update ()
{
	if (Input.GetButtonDown("Fire1"))
	{
		TheSword.animation.Play("AttackSword"); //plays animation where ButtonDown is called
	}
}
	
	
	
function ButtonDown(){

		//AttackDamage();
		var hit : RaycastHit;
		if (Physics.Raycast (transform.position, transform.TransformDirection(Vector3.forward), hit))
		{
			Distance = hit.distance;
			if ( Distance < MaxDistance)
				{
					hit.transform.SendMessage("ApplyDamage", TheDamage, SendMessageOptions.DontRequireReceiver);
					Debug.Log("hit");
				}
		}
	
}

At least you now know that the animation is NOT calling your method.
Try this:

 function Update ()
 {
     if (Input.GetButtonDown("Fire1") && canAttack)
     {
         TheSword.animation.Play("AttackSword"); //plays animation where ButtonDown is called
         canAttack = false;
         ButtonDown();
         StartCoroutine(WaitToAttack(1));
     }
 }
     
     
     
 function ButtonDown(){
 
         //AttackDamage();
         var hit : RaycastHit;
         if (Physics.Raycast (transform.position, transform.TransformDirection(Vector3.forward), hit))
         {
             Distance = hit.distance;
             if ( Distance < MaxDistance)
                 {
                     hit.transform.SendMessage("ApplyDamage", TheDamage, SendMessageOptions.DontRequireReceiver);
                     Debug.Log("hit");
                 }
         }
     
 }

function WaitToAttack (waitTime : float) {
    // suspend execution for waitTime seconds
    yield WaitForSeconds (waitTime);
    canAttack = true;
}