- Home /
[Solved it] Disable Camera Movement on Pause (C#)
Alright quick question. I tried looking around first and I am either dumb and don't know how to implement something, or something else is wrong. So I attempted to give my game the ability to pause, and for the most part I was successful. My only problem now is the camera still moves when the game is paused. I know that I am supposed to find the first person camera script and disable it but everything I try throws up errors. Here is my script so far without any of my attempts to fix the camera.
// Use this for initialization
void Start ()
{
}
void Update ()
{
if (!isPaused)
{
if (Input.GetKeyDown(KeyCode.Escape))
{
pause();
}
}
else
{
if (Input.GetKeyDown(KeyCode.Escape))
{
pause ();
}
}
}
void pause ()
{
if (!isPaused)
{
isPaused = true;
Time.timeScale = 0;
}
else
{
isPaused = false;
Time.timeScale = 1;
}
}
void OnGUI()
{
if (isPaused)
{
GUI.skin = boxSkin;
GUI.Label(new Rect(500,175,200,55), "Paused");
}
}
}
nevermind, i figured it out, i just added a second script for the camera, because it turns out the controller mouselook controls up and now and the camera mouselook controls left and right. I then added 'GetComponent().enabled = false;' to both scripts and 'GetComponent().enabled = true;' on the else. I also removed the gui component on the camera so I didn't get Two pause words.
Answer by Waffle842 · Oct 18, 2013 at 07:06 PM
nevermind, i figured it out, i just added a second script for the camera, because it turns out the controller mouselook controls up and now and the camera mouselook controls left and right. I then added GetComponent().enabled = false;
to both scripts and GetComponent().enabled = true;
on the else. I also removed the gui component on the camera so I didn't get Two pause words.
like so { if (!isPaused) { isPaused = true; Time.timeScale = 0; GetComponent<MouseLook>().enabled = false; } else { isPaused = false; Time.timeScale = 1; GetComponent<MouseLook>().enabled = true; } }
Could you put up an example script that has the new code included because I tried it and I get errors :(
Your answer
Follow this Question
Related Questions
Making a bubble level (not a game but work tool) 1 Answer
Head Bobbing Effect is Glitching Out on Collision 0 Answers
Keeping an object constrained to a 2d radius based off of the camera 0 Answers
Disable Camera Movement,Stop camera movement 0 Answers
Regarding transform.position in the roll a ball tutorial 1 Answer