Call a function dependent on frame of animation?

Basically, I have an attack function, and if I call it the same time I play the attack animation, the damage happens at the start of the animation, not when it looks like the sword hits him.

I’ve tried using animation.time, but this seems buggy, because sometimes the function gets called twice, sometimes it doesn’t at all, so it does twice the damage or it does none sometimes.

Is there A better way I can call the function dependent on the player’s animation?

It is possible to call a function on a specified frame of an animation.

Have a look at AnimationEvent

You can add an Event to a certain animation frame with the Unity Animation Editor.
It’s simply a function call to attached scripts at the given time.
The button for that is just aside the add keyframe button.