public void FreezeRigidbody(Rigidbody rigidbody) { StoredPhysicsData storedPhysicsData = rigidbody.gameObject.GetComponent <StoredPhysicsData>(); if (storedPhysicsData == null) { storedPhysicsData = rigidbody.gameObject.AddComponent <StoredPhysicsData>(); } if (storedPhysicsData != null) { storedPhysicsData.StoreDataFromRigidBody(rigidbody); } rigidbody.constraints = RigidbodyConstraints.FreezeAll; rigidbody.useGravity = false; }
public void UnFreezeRigidbody(Rigidbody rigidbody) { if (rigidbody.constraints != RigidbodyConstraints.None) { rigidbody.constraints = RigidbodyConstraints.None; rigidbody.useGravity = true; rigidbody.ResetInertiaTensor(); StoredPhysicsData storedPhysicsData = rigidbody.gameObject.GetComponent <StoredPhysicsData>(); if (storedPhysicsData == null) { storedPhysicsData = rigidbody.gameObject.AddComponent <StoredPhysicsData>(); } if (storedPhysicsData != null) { storedPhysicsData.SetRigidbodyFromStoredData(rigidbody); } } }