Edit - Code isolation using random ID numbers C#

void OnTriggerEnter(Collider otherParticle){
//makes sure the code only happens when you collide with another prefab sphere.
if (otherParticle.gameObject.tag == “Proton”) {
//add the mass of this sphere to the other sphere
otherParticle.rigidbody.mass = rigidbody.mass + otherParticle.rigidbody.mass;
//destroy this sphere leaving only the other sphere containing the combined mass
Destroy (gameObject);

I have these spheres. These spheres are programmed to gravitate towards one another. On the collision I want to add the mass of them together and the result be a single sphere. I’m still also trying to figure out the radius increasing upon combining them. Help with that, too, would be sweet!

To elaborate, this script is applied to every sphere I have in the scene. My issue is with the fact that upon collision both spheres are destroyed. I understand the code is being ran on both objects because the sphere collider trigger is the same radius on both of them so both spheres issue the code upon collision. I have to tried reduce the size of the sphere collider set as a trigger and the regular sphere collider, so that they are contained within the mesh of the sphere. Using the transport controls for the colliders, I set them apart from each other within the sphere mesh. I was hoping that if the collider on one entered only the collider trigger on the other then only one of them would be destroyed, but it seems that OnTriggerEnter issues two different ways. When this game objects collider enters another gameobjects collider trigger and also when this gameobjects collider trigger is entered into by another gameobjects collider.

I need help isolating this code to only one of the spheres! PLZ :slight_smile:

Manager pseudo code as follows

// On the particle
ParticleManager.DestroyMe (gameObject, otherGameObject);

// The Manager
public void DestroyMe (GameObject go1, GameObject go2){
    if (go1 && go2){
        Destroy (go1);

An alternate solution without the manager would be to use unique IDs. I’ve used a random number, but you could also use a static int to generate the ID. Pseudo code:

public float ID = Random.Range(0f,10f);

// Inside the collision code
if(ID > other.ID){