How do I unparent an object by scripting

How do I unparent the object once i stop holding down the mouse button?

  if (Input.GetKeyDown(KeyCode.Mouse1))
        {
            GameObject.transform.parent = gameObject.transform;
        }
        else if (Input.GetKeyUp(KeyCode.Mouse1))
        {
            GameObject.transform.parent = gameObject.transform;
        }

I fixed the problem by using null

  if (Input.GetKeyDown(KeyCode.Mouse1))
         {
             GameObject.transform.parent = gameObject.transform;
         }
         else if (Input.GetKeyUp(KeyCode.Mouse1))
         {
             GameObject.transform.parent = null;
         }

@thepotatisbulle I know I’m a little late to the party with this answer, but luckily Unity provides a function for that.

transform.DetachChildren();

This places the responsibility on the parent gameObject to let go of all its children.