- Home /
save 2D gameobject movement - for pause resume
I found script to save the movement(velocity) of a 3D object for pause. But I cant apply it to 2D object. I want to use this for pause menu but I dont want to set timescale to 0. The script I found was:( I am a newbie, help please:))
void OnPauseGame()
{
savedVelocity = rb.velocity;
savedAngularVelocity = rb.angularVelocity;
rb.isKinematic = true;
}
void OnResumeGame()
{
rb.isKinematic = false;
rb.AddForce(savedVelocity, ForceMode2D.Force);
rb.AddTorque(savedAngularVelocity, ForceMode2D.Force);
}
Comment