collider hit

hi all
i have an character with an sword that sward have an box collider.
i want when sword hit enemy collider box then decrease enemy heatpoint.
how?
how can i know when sword is hit enemy collider box?
thankful.

You want to take a look at-

or

When one of these occurs, you decrease the variable for your hitpoints in the enemy script.

sword or enemy has to have a rigidbody attached (likely the enemy if you’re using the CharacterController)

i do this but when my character is idle and enemy attack then nothing happens.
when i use box collider it dont work correct but when i use character controller its correct why?
you have an example code that work?
thankful.