2D Collider Problem
This line of code keeps getting called after I had changed my players 2Dcollider from the circle to a box with the exact same settings. This means after a few seconds the player just dies. I will provide the code getting called repeatedly and a screenshot of the box collider settings.
void OnTriggerEnter2D(Collider2D other)
{
if (timer >= timeBetweenAttacks && playerHealth.currentHealth > 0)
{
Attack();
}
}
Answer by andzq · Oct 15, 2016 at 01:34 AM
i don´t know how your game looks like, but maybe the problem is that you do not ask which collider enters your trigger. Without a check that usually looks like the following example every single gameObject with a 2D-Collider that comes in contact with the gameobject that has this script attached will trigger this Attack()-function.
void OnTriggerEnter2D(Collider2D other)
{
if(other.gameObject.tag == "myTag")
{
// your code here
}
}
That check is called in the Attack function. Plus perhaps I should have mentioned this was working perfectly fine before I swapped the colliders.