- Home /
How to call only ONE OnCollisionEnter, on one of two objects
I have two objects. Let's say we have script with one variable. On collision i want to either delete colliding objects, and create new one with their variables added, or just destroy one object and add its variable to second one. So far i always encountered some cloning, then there are more than 2 colliders colliding in one frame. Variables would be too high. 8 objects with '1' value -> 1 object with 8-16 value. One object can pass values to many objects without being deleted by other object.
$$anonymous$$y code is rather long, I'll post only necesarry part. http://pastebin.com/1jE0jqyz ID in last nested if was supposed to make it called only by one object, but for some reason it still gets called few times. Sometimes it assigns value before it's destroyed. It's assigned from static int s in code: ID = s++;
EDIT: I uploaded it to pastebin, I have no idea for to format code properly here.
Answer by PatPL · Oct 16, 2016 at 12:19 PM
OK, i fixed it. I created a static list in other script. It gets all objects that collided in this frame, adds their value, assigns it to object with highest ID and deletes every other object. Code: http://pastebin.com/Kx67Q3D5