Search Unity

how to stop character eye movement/control in the pause menu screen?

Discussion in 'Scripting' started by darkmon54, Sep 6, 2021.

  1. darkmon54

    darkmon54

    Joined:
    Sep 6, 2021
    Posts:
    4
    so im working on a 1st person flatformer game and im wondering how you stop the player's look movement/control in the pause menu since i just made.... (copy) a script for a pause menu and i dont know to stop my character from looking to different directions to access my pause menu here's my pause menu script and if you guys want the camera view script just let me know thank you in advance!
    Code (CSharp):
    1. using System.Collections;
    2. using System.Collections.Generic;
    3. using UnityEngine;
    4.  
    5. public class pausemenu : MonoBehaviour
    6. {
    7.   public static bool gameispaused = false;
    8.   public GameObject Pausemenu;
    9.     void Update()
    10.     {
    11.       if (Input.GetKeyDown(KeyCode.Escape))
    12.       {
    13.         if (gameispaused)
    14.         {
    15.           resume();
    16.         }
    17.         else
    18.         {
    19.           pause();
    20.         }
    21.       }
    22.     }
    23.  
    24.     void resume()
    25.     {
    26.       Pausemenu.SetActive(false);
    27.       Time.timeScale = 1f;
    28.       gameispaused = false;
    29.     }
    30.     void pause()
    31.     {
    32.       Pausemenu.SetActive(true);
    33.       Time.timeScale = 0f;
    34.       gameispaused = true;
    35.     }
    36. }
    37.  
     
  2. Kurt-Dekker

    Kurt-Dekker

    Joined:
    Mar 16, 2013
    Posts:
    38,726
    You did not post it but I will speculate that your "look" code does not pay attention to timeScale.

    This is common because look code often uses delta mouse movement, which already HAS timeScale "baked into" it.

    The usual way I handle it is in my look code Update(), just return if timeScale is zero.
     
    darkmon54 likes this.
  3. darkmon54

    darkmon54

    Joined:
    Sep 6, 2021
    Posts:
    4
    thank you for the information! this really helps alot! thank you very much!
     
    Kurt-Dekker likes this.