This question was
closed Dec 15, 2015 at 12:18 AM by
Phunmunkee for the following reason:
The question is answered, right answer was accepted
Question by
Phunmunkee · Oct 24, 2015 at 01:33 PM ·
script.
Pause Script problems
My pause script pauses the game, but it doesn't unlock the cursor or make it visble, also how do I make it unpause? Here's the code.
using UnityEngine; using System.Collections;
public class Pause : MonoBehaviour {
// Update is called once per frame
void Update () {
if (Input.GetKey(KeyCode.Escape)){
Time.timeScale =0;
Cursor.visible = true;
Cursor.lockState = CursorLockMode.None;
}
}
}
Comment
Best Answer
Answer by ElDo · Oct 28, 2015 at 08:07 PM
this works fine for me:
bool paused = false;
void Update() {
if (Input.GetKeyDown(KeyCode.Escape) && !paused) {
Time.timeScale = 0;
Cursor.visible = true;
Cursor.lockState = CursorLockMode.None;
paused = true;
} else if (Input.GetKeyDown(KeyCode.Escape) && paused) {
Time.timeScale = 1;
Cursor.visible = false;
Cursor.lockState = CursorLockMode.Locked;
paused = false;
}
}
Follow this Question
Related Questions
i need help with my script 1 Answer
Help with spawning Prefabs that go towards a player 2 Answers
Move a separate object forward on collision between particle system and another object 0 Answers
terrain deformation 0 Answers
Is this possible to script? 0 Answers