Remove life from builds (js)

Im trying an strategy game, i have an scrips that does soldier walk to the closest build and stand up in front of at X distance. Builds have another with health.
What I need to do is:
When soldier is in front of build attacking (melee), how can I remove life from build??

Help pls! :smiley:

  • “Health” is nothing more than int or float in most cases.

  • “Attacking” is removing a portion from that int or float.

  • Store house health in separate script, and place it on house itself.

    var health : float = 100f;

  • When attacking, from enemy get component from house script and reduce its health.

A lot of examples for getcomponent:

  • Additionally, you should create “cooling” methods, so enemy would not attack it every frame - kill house in blink of an eye.

Wait some time, till next attack: Unity - Scripting API: WaitForSeconds