Trigger not working on Enemy Prefab
Hi, i have a player tagged Head and some enemys which will be instantiated randomly.
My enemy is an animated Sprite. i put a script on it which let him move and play attack animation if it hits the player. But the trigger does not get activated. My player have box collider with trigger enabled and circle collider without trigger, he is tagged as "Head". My enemy has circle collider. I made some tests but its still not triggering using this function void OnTriggerEnter2d(Collider2D coll) { if (coll.tag == "Head") { ani.Play("EnemyAttack1"); } }
Please, wth im doing wrong?
Answer by hvd · Nov 28, 2015 at 10:24 AM
oops i forgot that that the method name is case sensitive, so i wrote OnTriggerEnter2d
instead of OnTriggerEnter2D
. Problem solved
Answer by OncaLupe · Nov 27, 2015 at 11:48 PM
The method is 'OnTriggerEnter2D', notice the capital D.
http://docs.unity3d.com/ScriptReference/Collider2D.OnTriggerEnter2D.html
Answer by Mohamor2000 · Nov 28, 2015 at 10:46 AM
you need to write :
void OnTriggerEnter2D()
{
print("do");
}
and be fun :D