OnTriggerExit2D called by untagged objects

Hey all,

I’m using a Trigger that switches a boolean value dependant on whether the character is within the collider or not. For some reason when enemies instantiate a projectile that leaves this trigger, the same bool value is switched even though the objects are not tagged as “Player”.

void OnTriggerExit2D(Collider2D fly){
		if (fly.gameObject.tag == "Player" && !RedControllerScript.animalRide && fly.rigidbody2D.tag == "Player")
			flightToggle = false;
			RedControllerScript.doubleJump = true;
			RedControllerScript.glide = true;
	}

doubleJump and glide should only be switched to true when the player leaves the trigger. I added the fly.rigidbody2D.tag to see if that would help but it did not change anything. I’ve noticed that removing the rigidbody2D from the instantiated projectile will stop the boolean value switching taking place.

Many thanks in advance,

Takz

You forgot the if’s braces, so you were accidentally inlining:

void OnTriggerExit2D(Collider2D fly){
    if (fly.gameObject.tag == "Player") {
        flightToggle = false;
        RedControllerScript.doubleJump = true;
        RedControllerScript.glide = true;
    }
}