- Home /
How to make camera stop moving in pause menu?
I've got a pause menu for my game, but the camera still moves in the background making it difficult to click the buttons. Any suggestions?
Is your pause menu actually using http://docs.unity3d.com/ScriptReference/Time-timeScale.html to stop game time? You could make your camera movement dependent on Time.deltaTime and pause would effect it as well.
Answer by Le-Capitaine · Sep 06, 2014 at 03:27 PM
What you could do is first to make a bool called pause
and set it to true/false when you pause/unpause. I recommend a dedicated Pause () function:
void Pause () {
pause = !pause;
//and maybe some extra bells and whistles in here
}
Then you'd just have your camera code executed only if pause
is false. To make things clearer, you could also move your camera code to another function named, like, CameraUpdate () or something and call it where your camera code used to be.
void Update () {
if (!pause) CameraUpdate ();
}
I'm not the best at sticking script together (or knowing where), could you be more specific?
You can put your functions anywhere within the largest brackets. So, above Start, between Start and Update, below Update, below all other functions, or anywhere that isn't inside a function.
using UnityEngine;
using System.Collections;
public class $$anonymous$$yCoolClass : $$anonymous$$onoBehaviour
{
public int myCoolInt;
bool pause;
void Start () {
//things here
}
void Update () {
if (!pause) CameraUpdate ();
}
void SomeCoolNewFunction () {
//cool things here
}
void CameraUpdate () {
//your camera code here
}
void Pause () {
pause = !pause;
//extra pausey code here
}
}
!
literally means "not" in coding. !pause
is a handy shorthand for "not pause
" that returns false if pause is true and vice versa. It's slightly different in if
statements where writing a bool is a shorthand for getting its state, so if (pause)
is shorthand for if (pause == true)
.
Your answer
Follow this Question
Related Questions
Multiple Cars not working 1 Answer
Script Not workin 1 Answer
Zelda like pause menu 1 Answer
How do I turn the Main Camera 90 Degrees on the X axis 2 Answers
Creating Pause Game Menu 1 Answer