How do I make an object kinematic on button press then, non-kinematic when I release the button

I have looked everywhere for a script to make a prefab Kinematic on button press and then non-Kinematic when you release it. I really have no script and there is no tutorial explaining this.

Use the ! (not) symbol in your call.
GetComponent<RigidBody>().IsKinematic = !GetComponent<RigidBody>()IsKinematic;

Which will set it to the opposite of what it currently is. So you can put this in your button event function, and the first press will have it on (if it started off), and then the second press will have it off, and itll continue that process every time the button is pressed.

If you wanted to do a system where while the button is held down, its on, then when the button is lifted up and no longer being pressed, its off, you could do something like:

public void KinematicOn(){GetComponent<RigidBody>().IsKinematic = true;}
and
public void KinematicOff(){GetComponent<RigidBody>().IsKinematic = false;}

Then, use a Event Trigger to register a “Pointer Down”, and “Pointer Up”, or use Unity’s built-in event listeners function (I believe their called) OnMouseDown, and OnMouseUp – for example:
void OnMouseDown(){GetComponent<RigidBody>().IsKinematic = true;}

But I think these events (OnMouseDown and Up), need the object to have some type of collider to register, but I could be wrong.