Car is deleted when under void OnCollisionEnter2D(Collision2D other)

I’m wanting to make it an object that is moved, changes its sprite then disappears.
the package moves, is crushed, but then the car is deleted instead.
What am I doing wrong?

    void OnCollisionEnter2D(Collision2D other) 
    {
        if(gameObject.tag=="SpeedBump")
        {
            Debug.Log("Splat!");
            isAlive = false;
            ChangeSprite();
            Destroy(other.gameObject, 3f);    
        }
        
    }

Just the package is tagged SpeedBump, and not the car.

Welcome to the community, @VenganzaD

You are checking this object’s tag. Then you destroy the object that collided with it. I am assuming this script is on the package. Change this

Destroy(gameObject, 3f);

You are destroying the car instead of the package.

1 Like

This topic was automatically closed 24 hours after the last reply. New replies are no longer allowed.

Privacy & Terms