- Home /
Stop force from being applied during pausescreen
Hello,
I'm making a 2d topdown game and I seem to be having a problem I want to fix.
I'm using Time.timeScale = 1;
and Time.timeScale = 0;
in order to pause and unpause my game.
I am also using addRelativeForce to my rigidbody (Physics2D) whenever I press WASD in order for my character to move.
When I "pause" the game and press any WASD button and "unpause" the game, the force is applied to my character.
Is there any way for me to fix this or stop actions from happening?
Here is my pause screen code:
bool paused = false;
GameObject pauseGUI;
GUITexture pauseScreen;
// Use this for initialization
void Start () {
pauseGUI = GameObject.Find ("PauseScreen");
pauseScreen = pauseGUI.GetComponent<GUITexture> ();
}
// Update is called once per frame
void Update () {
if(Input.GetKeyDown(KeyCode.Escape) && paused == false)
{
paused = true;
Time.timeScale = 0;
pauseGUI.SetActive(true);
pauseScreen.enabled = true;
}
else if(Input.GetKeyDown(KeyCode.Escape) && paused == true) {
paused = false;
Time.timeScale = 1;
pauseGUI.SetActive(false);
pauseScreen.enabled = false;
}
}
}
Comment
Best Answer
Answer by robertbu · Feb 16, 2014 at 04:58 AM
You can just add this to the top of Update():
if (Time.timeScale < 0.1) return;
I added it to the top of my movement code ins$$anonymous$$d of update and it works! Thanks!