- Home /
Question by
lsp34 · Dec 09, 2017 at 02:32 PM ·
scripting problemunity 2dtimescalemouse-dragpause game
How to make player not movable when paused?
hello, when i pause the game the player is still drag-able what I need to do to fix this? this is for the player movement
void OnMouseDrag() {
var point = Camera.main.ScreenToWorldPoint(new Vector2(Input.mousePosition.x,
(transform.position.y - Camera.main.transform.position.y)));
point.z = transform.position.z;
transform.position = point;
}
this is for the pause
public void Pause () {
Time.timeScale = 0;
gamePausedPanel.gameObject.SetActive (true);
}
Comment
Best Answer
Answer by Stefan02 · Dec 09, 2017 at 03:37 PM
Use the boolean. If player paused the game set bool to true, if player is playing the game bool is false.
public static bool paused = false;
void OnMouseDrag() {
if(paused == false){
var point = Camera.main.ScreenToWorldPoint(new Vector2(Input.mousePosition.x,
(transform.position.y - Camera.main.transform.position.y)));
point.z = transform.position.z;
transform.position = point;
}
}
public void Pause () {
paused = true;
Time.timeScale = 0;
gamePausedPanel.gameObject.SetActive (true);
}
Put all code into one script to avoid sharing the value with other script.
Your answer
![](https://koobas.hobune.stream/wayback/20220612144254im_/https://answers.unity.com/themes/thub/images/avi.jpg)