Hello,
In my game, objects are instantiated on the screen one by one from an array of GameObjects, by being cloned. On collision both objects collided disappear because I write:
void OnTriggerEnter2D(Collider2D other)
{
print("hit detected");
Destroy(gameObject);
}
However I would like only for latter instantiated object to be destroyed.
The problem is that I have to put this method on each of the instantiated objects, which will be randomly instantiated, so they all have the collider2d and they all get destroyed on contact as they all have the OnTriggerEnterMethod().
How will the program distinguish that only the last one should get destroyed?