Collision2D enable/disable problem
So i have my player and a box(has a non trigger box collider2d) that i tagged with "Player" for testing. My player has a rigidbody2d and so does the box, they are not kinematic. I put a box collider which is a trigger as a child to the player. The box collider does not have a rigidbody. When i come close to the box"Player" i press F to enable the box collider(a child to the player) the function OnTriggerEnter.. gets called and i get a log message and the box collider gets disabled; HOWEVER if i press f again while the disabled box collider is still in the box"Player" it does get enabled but DOES NOT call the function OnTriggerEnter... When i move and press f, then come close to the box"player" the OnTriggerEnter.. gets called again. So in summary my problem is that i cant spam F and enable/disable the box collider because while it appears in the box"player" it does not call the function OnTriggerEnter. To my box collider this script is attached:
 public int dmg = 20;
 public bool damaging = false;
 void OnTriggerEnter2D(Collider2D col){
 
     if (col.CompareTag ("Player") && col.isTrigger != true && damaging == false) {
     
         damaging = true;
         Debug.Log ("Entered and damaged");
         col.SendMessageUpwards ("Damage", dmg);
     }
     Debug.Log ("Entered");
 }
 void OnTriggerExit2D(Collider2D col){
     
     damaging = false;
     Debug.Log ("Left");
 } 
Is this just how it works? if so is there any way to go around that? If not is it a mistake on my part?
Answer by MagicCreator · Apr 10, 2018 at 10:45 AM
I got around this problem by using Physics2D.BoxOverlap when i click attack instead of enabling and disabling the collider. Using the function above is actually a very good and clean way to do fightin g because you can see which collider u overlapped with.
Your answer
 
 
              koobas.hobune.stream
koobas.hobune.stream 
                       
                
                       
			     
			 
                