Pause Menu and Cinemachine

Hi, guys!

I’m trying to work on an university assignment, and I am having some trouble to set the Pause Menu up with a Cinemachine. The Code the professor shared is this one:

using UnityEngine.SceneManagement;
using UnityEngine;

public class PauseMenuController : MonoBehaviour
{
    public GameObject pauseMenuCanvas;
    [B]public FirstPersonLook fpl;
    public Zoom zoom;[/B]
    public AudioSource aS;

    private bool isPaused;

    private float fixedTime;

    // Start is called before the first frame update
    void Start()
    {
        isPaused = false;
        fixedTime = Time.fixedDeltaTime;
        pauseMenuCanvas.SetActive(false);
    }

    private void PauseGame()
    {
        isPaused = false;

        [B]fpl.enabled = false;
        zoom.enabled = false;[/B]
        aS.Pause();
       
        Cursor.visible = true;
        Cursor.lockState = CursorLockMode.None;

        Time.timeScale = 0;
        Time.fixedDeltaTime = 0;

    }

    public void ResumeGame()
    {
        pauseMenuCanvas.SetActive(false);
   
      [B]  fpl.enabled = true;
        zoom.enabled = true;[/B]
        aS.Play();
        
        Cursor.visible = false;
        Cursor.lockState = CursorLockMode.Locked;
        
        Time.timeScale = 1;
        Time.fixedDeltaTime = fixedTime;
    }

    public void GoToMainMenu()
    {

        ResumeGame();
        SceneManager.LoadScene(1);
    }

    public void QuitGame()
    {
      
#if UNITY_EDITOR
        UnityEditor.EditorApplication.isPlaying = false;
#else
            Application.Quit();
#endif
    }

    // Update is called once per frame
    void Update()
    {
        if (Input.GetKeyDown(KeyCode.P))
        {
            isPaused = !isPaused;

            //Idem "if(isPaused == true)"
            if (isPaused)
            {
                PauseGame();
            }
            else
            {
                ResumeGame();
            }
        }
    }
}

I understand that the parts I’ve put in Bold refer to the scripts on the Camera the professor is using. But since I’m using another Player (it’s actually Starter Assets Third Person), and it uses Cinemachines instead of C# Scripts, I have no idea on how to refer to them on the Pause Menu Script.

Would be really happy if I could get some help here!

Thank you all!

I assume that those FirstPersonLook and Zoom where doing something to camera when they were attached to normal camera not using cinemachine virtual camera. If you just want to pause camera movement when in pause menu you don’t need any of those references when using Unity Starter Assets Third Person it it enough just to set Time.timeScale and camera won’t move cause in that pack camera is rotated in third person controller late update and uses Time.deltatime to calculate input so when you set Time.timeScale to 0.0f your time.deltatime will be 0.0f and camera won’t move.

Hope that helps :wink:

1 Like