- Home /
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);
}
Answer by syclamoth · Sep 22, 2011 at 03:48 AM
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
}
Sorry I'm still confused. I'm very new to the scripting world. I looked up some stuff on boolean. But I'm not sure what to do. Does the boolean make it so the sword's collision is off when I'm not attacking? I basically want to have character only do damage when the sword collides with the enemey but only when I push my attack command. DId you mean I have to add the boolean to the my Sword script? Sorry for the many questions
Yes, in your sword script set the boolean to true when the attack begins, and the set it to false when the attack ends.
Your answer
Follow this Question
Related Questions
Urgent help for Unity Game with deadline tomorrow 0 Answers
Damage Meter 1 Answer
How to have deformation/denting of 2D objects on impact? 1 Answer