hello i am trying to freeze my cube with script so when press R they have to freez in the position that they are this code is working but behaves very strange sometimes they countiniusly moove when freezed.
if (Input.GetKeyDown (KeyCode.R)) {
GetComponent<Rigidbody>().constraints = RigidbodyConstraints.FreezePositionX | RigidbodyConstraints.FreezeRotationZ;
GetComponent<Rigidbody>().constraints = RigidbodyConstraints.FreezePositionY | RigidbodyConstraints.FreezeRotationY;
GetComponent<Rigidbody>().constraints = RigidbodyConstraints.FreezePositionZ | RigidbodyConstraints.FreezeRotationX;
}
if (Input.GetKeyUp (KeyCode.R)) {
// the direction to leap towards mouse
Physics.gravity = new Vector3 (0, -6.0F, 0);
}