- Home /
Attack Player if Enemy is hit
Hello I have this script that works perfect but I tried to add this to my script but it did not work for some reason
function OnTriggerEnter(col : Collider) {
if(col.gameObject.tag == "Bullet"){
gameObject.SendMessage("attack");
}
}
its supposed to make the enemy execute "attack" function when the bullet hits him. And the attack is a function that makes it follow the player
Felipe
any errors? what do you want to achive?
you need to be more detailed.
sfc
the script works but when I shoot at the enemy with the bullet nothing happens. I also edited the question
first check that the bullet has the right tag.
dose the bullet enter the trigger?
cause if you have 2 colider and no one has istrigger then it never enters the trigger.
or change it to OnCollisionEnter .
and does one of them has rigidbody?
sfc
well, I would put it on the bullet, first off:
function OnTriggerEnter(col : Collider) {
Debug.Log("in trigger");
if(col.gameObject.tag == "enemy"){
col.gameObject.Send$$anonymous$$essage("attack");
}
}
I think that should work
Your answer
Follow this Question
Related Questions
How to make enemy damage in diferent parts of the object? 2 Answers
Enemy death help 1 Answer
Health and ApplyDamage to tagged objects - Help 1 Answer
How can i make a projectile attack travel through multiple enemies dealing damage to all of them? 1 Answer
How do I go about adding basic pathfinding to my enemy? 1 Answer