How do I detach an object trough scripting?

Hi, I’m new to Unity and I have a rocket that has 2 stages, I need to detach 1 stage trough scripting before releasing the parachute, how can I achieve this?

If it is connected via transform parentage (hierarchy), you can set the parent of the piece coming off to null.

public GameObject detachingPart;

void Detach()
{
  detachingPart.transform.SetParent(null);
}
1 Like