Pause Menu Help

Updated on March 3, 2018 in [C] Beginner
Share on Facebook0Tweet about this on TwitterShare on Google+0Share on Reddit0
5 on March 1, 2018

Hello, im very new at this and was wondering how to make the mouse stop moving the camera when I click escape, i’ve been following along with the https://www.youtube.com/watch?v=JivuXdrIHK0 ‘Pause Menu in unity’ video but would like to add this feature. Thanks

  • Liked by
Reply
0 on March 1, 2018

If you multiply the cameras movement speed by Time.timeScale, then when timeScale is 0 (i.e. the game has been paused) the camera will be moving 0 units per frame. So it wont be moving at all.

  • Liked by
Reply
Cancel
3 on March 2, 2018

using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.SceneManagement;

public class PauseMenu : MonoBehaviour {

public static bool GameIsPaused = false;

public GameObject pauseMenuUi;

// Update is called once per frame
void Update () {
if (Input.GetKeyDown (KeyCode.Escape)) {
if (GameIsPaused) {
Resume ();
} else {
Pause ();
}
}
}
public void Resume ()
{
pauseMenuUi.SetActive (false);
Time.timeScale = 1f;
GameIsPaused = false;
}

void Pause ()
{
pauseMenuUi.SetActive (true);
Time.timeScale = 0f;
GameIsPaused = true;
}

public void Back ()
{
pauseMenuUi.SetActive (true);
Time.timeScale = 0f;
GameIsPaused = true;
}

public void QuitGame()
{
Time.timeScale = 1f;
SceneManager.LoadScene (0);
}
}

 

 

That’s my script,  when its paused it’s Time.timeScale = 0f; yet the mouse still moves? Not sure whats wrong

on March 2, 2018

That’s probably because you don’t do anything with time in the camera. Setting timeScale ONLY affects objects that are dependent on thing like deltaTime.

 

Ex of object dependent on deltaTime:

void Update
{
    transform.Rotate(Vector3.up, rotationSpeed * Time.deltaTime);
}

 

Ex of object NOT dependent on deltaTime:

void Update
{
    transform.Rotate(Vector3.up, rotationSpeed);
}

 

Both of the Update loops above do the same thing. The one with deltaTime will do it slower because it’s being multiplied by a number less than 1, but they both will still rotate the object on its Y axis based on rotationSpeed. The difference is the top one is time dependent, while the bottom one only cares about the overall frame-rate of the game.

on March 3, 2018

I’m so sorry, I don’t want to be this annoying, I understand what you mean but I don’t know how to implement that into the script or what to really do. Like I’ve tried but when I try to add it to the update part it says rotationSpeed is not right.

 

 

on March 3, 2018

rotationSpeed is just the name I made up for my example. You would need to put the name of the variable you’re using for the rotation speed. Can I see the camera script?

Show more replies
  • Liked by
Reply
Cancel