hi im trying 2 make it so when my characters sword blade mesh or box collider hits a enemy 5 times the enemy disappears i dont need the enemy 2 play a animation just 2 disappear my character already using animations for the attacking but i would like if possible 2 have it so only does damage if 1 of the attack keys are used but if u dont know how thats fine ether way is good my character is using this script for the animations
function Update()
{
if (Input.GetKey(“”))
{
animation.CrossFade(“”);
}
}
You probalby want to create an enemyscript and check if the enemy is hit by the sword. If it’s hit 5 times you can destroy the enemy.
try to attach this into your enemyscript (not tested)
var _collider : BoxCollider;
var health : float = 5;
function Start()
{
_collider = GetComponent(BoxCollider);
}
function OnCollisionEnter(col : Collision)
{
if(col.gameObject.tag == "Sword")
{
health--;
if(health <= 0)
Destroy(this.gameObject);
}
}
Note: you will need to add a tag (Sword) to the sword. And if you are not using a BoxCollider on the enemy, replace “BoxCollider” with your collidertype. (You will need a collider on the enemy just to make it clear)