- Home /
Need Some Help With "Pausing".
I've looked through a ton of questions on here about "pausing" a game. What I need to do is when I press a key on the keyboard, I need the camera to stop tracking the mouse, but the mouse still be functional to do other things, such as click on buttons on the GUI. How does one do this?
A lot of the answers I looked through say to grab the First Person Controller's MouseLook, and the MainCamera's MouseLook, and disable them. None of the codes that I have found seem to work. I also found a post recently that states the MouseLook changed in Unity5, so I'm assuming the answers worked in old versions, but not the most recent one.
I'm sure there is someone who ends up having to do this a lot, who can answer my question, and I will be forever grateful. Thank you.
Answer by Yuvii · Oct 13, 2017 at 11:40 AM
you can find the part of your code that make your camera move with the mouse, and just put it in an if() statement.
bool gamePaused = false;
void Upadte(){
if(Input.GetKeyDown(KeyCode.P))
gamePaused = !gamePaused;
if(!gamePaused)
{
"*your Camera's lookScript*"
}
}
or maybe i don't get your problem.. Could you share your script ?
Well, that's the problem. I don't have a script for this. Nothing that I try seems to work. I can handle initiating the script to make the camera stop moving, it's the part where you have "your camera's lookscript" that I'm having trouble with.
Would the time.timescale that @Zielscheibe recommended be a good idea? As long as the GUI is functional, and I can update values like enemies health, then I'm good. It's just a personal project I'm working on, so it doesn't have to be the most optimized script.
public bool isPause = false;
void Update()
{
if (Input.Get$$anonymous$$eyDown($$anonymous$$eyCode.P))
{
isPause = !isPause;
if (isPause)
{
Time.timeScale = 0;
}
else
{
Time.timeScale = 1;
}
}
}
This is what I have in there currently after trying the Time.timescale. That doesn't seem to be working either.
I'm not sure that Time.timeScale will pause your mouseLook script. But what do you mean by
I don't have a script for this
Even if it's some kind of asset you should be able to modify the script.
Answer by Zielscheibe · Oct 13, 2017 at 12:23 PM
You might also have a look at Time.timeScale.
If you set Time.timeScale = 0.0f everything that is time-dependent in your game, movement, animation, physics will freeze. The GUI, on the other hand, should remain functional.
Of course, this is a complex topic and there may be systems where you have your scripts to know whether the game is paused or not (like @Yuvii stated). Though, I don't know if this applies to your camera script or not.
Hope that helps :)
Your answer
Follow this Question
Related Questions
Multiple Cars not working 1 Answer
Distribute terrain in zones 3 Answers
Using quaternion for mouse movement? 3 Answers