Colliding damage on Enemy even when not attacking?

Hi everyone. I have a problem with my colliders. Right now I have a combo attack. I also have a sword that is attached to the hand. I’m able to do my combo moves and I’ve set a collision on my sword so that it can do damage when it comes into contact with the enemy. The only problem is…the collision happens even when I’m not doing my combo moves. If I stand close enough and let the sword just touch the enemy, it will do damage. Is there a code or script I have to add in to tell the collider to only work when i’m attacking?

Thanks. I’m doing this as a learning process and any help or tips would be appreciated.

Script for my Sword:


var damage : int = 10;

function OnTriggerEnter (other : Collider) {

  var Enemy : Enemy = other.GetComponent("Enemy");

if (Enemy != null)

    Enemy.ApplyDamage(damage);

}


1 Answer

1

Well, you can have a boolean value on your sword, which you set to true if you are attacking. Then, in your OnTrigger, do something like this-

if(attacking)
{
    // do damage things
}

Yes, in your sword script set the boolean to true when the attack begins, and the set it to false when the attack ends.

–