Collision, but then only affect ONE of the gameObjects?

[using iOS]

-- Hey everyone, I have a situation that i could use come guidance with. I need to randomly spawn some cubes in a predetermined space (like a 4x3 grid). While doing this, I some times get spawns at the same location. I tried testing for OnCollisionEnter, and then destroy the object, and trying again, only... that will destroy BOTH objects, since they get a "true" when they get their signal that they are colliding.

My question is, is there a way to ONLY do execute code for ONE of the objects, or two, a better way to do something like this in general. (like having each spawn point have a bool var that get's flipped to true if it ever spawns a cube at it's spot?)

Thanks in advance!

Here's my answer based on my interpretation of your question (with which I could use some help in the form of further explanation of your goals and methods)

Collisions happen at the same time. You can not discriminate who was first or last without using a time variable on the spawning of the object. Use a time to determine this and destroy the first or last based on that timer.

You could also random who dies by creating a random number between 0 and 1 and see if this object dies but then you would have to tell the other block to ignore the very same command of course so it would need to talk to the other object and pass that message.

You could also make a spawn system handle it, fill a 2D array with objects randomly without letting any overrides occur (so check for null), untill the array is full. You may want to not make a 10000 size 2D array for that with this random type of sorting though. Takes quite some time if it get's to huge.

Well with more info maybe I can give you a better answer ;)

Good luck in any case :)

to achieve this i created a do/while loop that randomly placed an object on a grid, checked an array of earlier placed objects to see if it was within the objects h/w plus the array objects h/w and if not, then finally place the object and add it to the array so i can place the next object. it was fun to figure that out.