Calling raycast function on animation dont work

So what im trying to do is when i press left mouse button animation plays and in middle of animation call function attack with will take some hp of another object but idk why but function is not working… ;\

Meele script

#pragma strict
var TheDammage : int = 50;
var Distance : float;
var MaxDistance : float = 1.5;
var TheSystem : Transform;

function Start () {

}

function Update () {
if (Input.GetButtonDown("Fire1"))
    {
        //Attack animation - IF YOU ARE GETTING ERRORS BECAUSE YOU HAVENT MADE AN ANIMATION AND ATTACHED IT, DELETE THE FOLOWING LINE.
        animation.Play("Swing");

    }
    }
    function attack() {
var hit : RaycastHit;
        if (Physics.Raycast(TheSystem.transform.position, TheSystem.transform.forward, hit, MaxDistance))
        {
           
                hit.transform.SendMessage("ApplyDammage", TheDammage, SendMessageOptions.DontRequireReceiver);
           
        }
        }

Enemy script

#pragma strict

var Health = 100;

function ApplyDammage (TheDammage : int)
{
    Health -= TheDammage;
   
    if(Health <= 0)
    {
        Dead();
    }
}

function Dead()
{
    Destroy (gameObject);
}

TheSystem is already a transform, so you don need to access its transform. Also, you should use GetComponent and not SendMessage.

Last remark: You have a function Attack, but you are not using it when the button is pressed.

It seems that you’re not calling the attack method in your code. Only specially named event method get called automatically by Unity. Any other methods have to be called explicitly.

Try changing your Update method to this:

function Update()
{
    if (Input.GetButtonDown("Fire1"))
    {
        animation.Play("Swing");
        attack();
    }
}

I call that function in middle of animation,add animation event and so on.

hmm cant i call function in animation event? like in middle of animation?

Show the relevant code that actually calls that function.