Resizing an object on collision in unity,Resizing an Object on Collision in unity

I have two objects - a bunch of asteroids and a sphere-CollisionSphere. Asteroids on collision with the sphere have to be destroyed and the sphere has to increase in size. As of now, the asteroids are getting destroyed- no problem however the size doesn’t seem to be changing of the sphere.

Could someone please help me…

this is my code

Vector3 temp;
private void OnCollisionEnter(Collision collision)
    {
        if (collision.gameObject.name == "CollisionSphere")
        {
            
            //Destroy(gameObject);
            gameObject.SetActive(false);

            temp += new Vector3(2, 2, 2);
            transform.localScale = temp;
        }
    }
  1. If this is your asteroid code, then why do you try to use temp varible? This will not work anyway, so let’s replace this with:
    collision.gameObject.transform.localScale +=new Vector3(2, 2, 2);
    2.Why do you trying to change scale of asteroid.
    3.Destroy asteroid AFTER change scale.

There you go fixed code:

 private void OnCollisionEnter(Collision collision)
     {
         if (collision.gameObject.name == "CollisionSphere")
         {
            collision.transform.localScale += new Vector3(2, 2, 2);

              //Destroy(gameObject);

             gameObject.SetActive(false);
         }
     }