Question by
hvd · Nov 30, 2015 at 09:48 PM ·
collidercollider2danimationevent
How to use Animation Event in this case ?
This thread was originally more complex i reduced it to one thing now. I have this code here to deal damage from enemys to my player parts.
public void OnTriggerStay2D(Collider2D coll)
{
HealthScriptSeg seghealth = coll.GetComponent<HealthScriptSeg>();
if (seghealth)
{
ani.Play("Enemy1Attack");
seghealth.HP -= DamageAmount*Time.deltaTime;
}
HealthScriptHead headhealth = coll.GetComponent<HealthScriptHead>();
if (headhealth)
{
ani.Play("Enemy1Attack");
headhealth.HP -= DamageAmount*Time.deltaTime;
}
}
You see i deal damage every second but thats not what i want. I like to have the damage at the end of every animation. So i need to use an 'animation event' but i dont know how to get a reference to 'Collider2D coll' to be able to make a new function 'Damage()' where i can use the information off 'coll' to know what part i will damage?
Comment
Answer by Rostam24 · Dec 04, 2015 at 09:23 AM
I do this: the animator fires an event, which does a raycast to determine closest target in attack vector. Thanks to the raycast, I can grab the relevant scripts and do damage.
Will this help you?