How to add rigidbody to a gameobject on a collision

Hi. I’m relatively new to scripting and i’m trying to make a basic game where when you hit something or when an object hits a certain game object, a rigidbody is applied to it causing it to fall apart. Im looking for someone to help me design a script that can make it so that the rigid body is applied when that object gets collided by a certain object. I can figure out most of the code beside the part of adding a new component to the object entirely through code. Help appreciated, thanks!

What you probably want to do instead of adding the rigidbody on collision, is to instead have it already have one attached, that is kinematic, and when the collision happens, make it non-kinematic.

You do AddComponent to add components to objects at runtime though!

3 Likes