Collision and destroying the gameObject

Hello guys, I have a new problem :face_with_spiral_eyes:

The problem is in collision and destroying my gameObject. I wrote the script:

using UnityEngine;

public class CollisionScript : MonoBehaviour {

    void OnCollisionEnter2D(Collision2D other)
    {
            Destroy(gameObject); 
    }

}

I made spawner and sometimes it can spawn 2 objects that can be ā€œone-on-oneā€, so I decide to make special script. When they will spawn ā€œone-on-oneā€ they will collide and then destroyed. In this way, I can avoid creating one-on-one objects.
But, the problem is that when they collide nothing happend. After some experiments I saw that the problem is in the ā€œRigidBody2Dā€ - Kinematic body type and if a change it to Dynamic - all is ok and object destroy. I need to made it without onTriggerEnter2D.

Please, help me :frowning:

Not to troll, but you should probably fix the problem at hand. The one on one spawning problem.
Never a good idea to try and patch a problem instead of solving it.
If you post the spawning problem maybe someone can help…

1 Like

The spawning problem in that that I have 3 methods. In these methods spawn of game objects occurs at random time for example Random.Range(1,3). So, I have 3 methods with 3 difficulties of spawning obstacles and problem the next:
for example: spawn of obstacles, then after 2sec must be next spawn of obstacles, but before when 2sec will last, probally could start another method(previous method will stopped) which will spawn new obstacles at this time and in this moment will be situation when obstacles will be ā€œone-on-oneā€.

Sorry for my English, it’s not my native :frowning:

It can be funny, but I followed your advice and have solved problem for 15min :slight_smile:
Thank you.

1 Like