- Home /
 
OnTriggerEnter2D on an empty game object with a box collider?
In my 2D RPG, I have a game object called "Player" that has a child object called "PivotPoint"; this child is empty but has a box collider. Then, I have a child of that object called "Sword" that actually has the sword sprite (and its parent object's box collider surrounds this sword). I did this because I was struggling with understanding how to rotate objects with scripts and this made it easier for me.
I made a script where when this empty object box collider collides with an enemy, the enemy will be destroyed:
 public class AttackEnemy : MonoBehaviour 
 {
     void Update()
     {
 
     }
 
     void OnTriggerEnter2D (Collider2D other)
     {
         if (other.gameObject.name == "Enemy") 
         {
             Destroy (other.gameObject);
         }
     }
 }
 
               This script does not work when I attach it to the object called "PivotPoint", even though this box collider is colliding with the enemy; it does, however, work when I place it on the parent object "Player" (however this no longer gives off the appearance of the sword doing the killing, so it's not what I want). Is there some rule where OnTriggerEnter2D doesn't work with an empty game object, or am I missing something that would allow this to work?
Answer by Sim0nGS · Jan 17, 2018 at 04:19 PM
Are you sure you have ticked the "IsTrigger" Box for the gameObject you want to attacht the script too? @SecretAgentMango
Your answer
 
             Follow this Question
Related Questions
OnTriggerEnter2D Doesn't work? ;_; 4 Answers
OnTriggerEnter not working in running game 4 Answers
Unable to get OnTriggerEnter to work.[JS] 2 Answers