- Home /
Unpausing While Keeping Values
I've done a lot of research and tried copying scripts exactly but because I'm using a 2d rigidbody I get unique problems.
I'm trying to get objects to pause and then continue on the same velocity and direction they were going before I paused
Currently my setup is using two scripts one that controls the gui pause button...
if (GUI.Button (new Rect (15, 30, 100, 50), "Pause")) {
boxClicked = !boxClicked;
and the other references "boxClicked" to stop the gameobject's rigidbody
public Vector2 savedVelocity;
void FixedUpdate()
{
Debug.Log (savedVelocity);
if (GlobalClockScript.boxClicked == true)
{
GamePlaying();
}
if (GlobalClockScript.boxClicked == false)
{
GamePaused();
}
}
void GamePlaying()
{
rigidbody2D.isKinematic = false;
rigidbody2D.AddForce (savedVelocity, ForceMode2D.Force);
}
void GamePaused()
{
savedVelocity = rigidbody2D.velocity;
rigidbody2D.isKinematic = true;
}
For some reason I'm unable to save the velocity value (savedVelocity) and deploy it as a force when I resume the game. Any help would be great
Could you give the link you are talking about to compare ?
By the way, I don't think that force and velocity are related in such a simple way.
http://answers.unity3d.com/questions/284068/pauseing-and-resu$$anonymous$$g-a-rigidbody.html
I based it off of this persons.