It seems my tag detection does not work properly
Here is part of the script:
void OnTriggerEnter2D (Collider2D other){ if (other.tag != "Player") { Destroy (gameObject, 0.01f); } }
it has been working until now, this tag is on my bullet and now when I shoot it collides with the players box collider (2D) and destroys itself. Its a child of the player by the way. To try and fix it I edited the physics 2d collisions settings for layers but it didn't change anything.
Thanks to those who tried helping but the script was not the problem. I am just stupid. The sprite of the bullet was not rendering in front of the other layers but behind. This is why it looked like it didn't leave the player's collider. It is wired tho that it was destroyed immediately. It works though which is nice.
Answer by KarMa_PlaYzz · Jan 14, 2018 at 08:31 PM
I'm not sure but have you tried changing != to == , or is this not what you meant?
Answer by ransomink · Jan 14, 2018 at 11:28 PM
Is this in the bullet script? Make sure both the player and bullet have the Player tag. Also, use CompareTag() instead...
void OnTriggerEnter2D( Collider2D other )
{
// Not the player?
if ( !other.CompareTag( "Player" ) )
{
// Get rid of this game object
Destroy( gameObject, 0.01f );
}
}