I have this below script in place to pause the FPS when I click on a note in the game, it will totally disable the movement of the player until they click again and the note closes.
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityStandardAssets.Characters.FirstPerson;
public class DisableManager : MonoBehaviour
{
public static DisableManager instance;
[SerializeField] private FirstPersonController player;
void Awake()
{
if (instance != null)
{
//Destroy(gameObject);
}
else
{
instance = this;
//DontDestroyOnLoad(gameObject);
}
}
public void DisablePlayer(bool disable)
{
if(disable)
{
player.enabled = false;
//disable crosshair
}
if(!disable)
{
player.enabled = true;
//enable crosshair
}
}
}
The problem comes when implementing a script for the pause and exit menu (below), The script opens and closes the pause menu (on ESC) along with a simple exit game button to go back to the main menu. When this script is enabled, the above disablemanager script doesn’t seem to be pausing the FPS anymore when reading a note (able to move around), and i’m not sure why, any help would be appreciated, thanks.
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.SceneManagement;
using UnityStandardAssets.Characters.FirstPerson;
public class SimplePauseMenu : MonoBehaviour
{
[SerializeField] private GameObject pauseMenuUI;
[SerializeField] private bool isPaused;
[SerializeField] private Transform Player;
private void Update()
{
if (Input.GetKeyDown(KeyCode.Escape))
{
isPaused = !isPaused;
}
if (isPaused)
{
ActivateMenu();
}
else
{
DeactivateMenu();
}
}
void ActivateMenu()
{
Time.timeScale = 0;
AudioListener.pause = true;
pauseMenuUI.SetActive(true);
Player.GetComponent().enabled = false;
Player.GetComponent().enabled = false;
Cursor.lockState = CursorLockMode.None;
Cursor.visible = true;
}
void DeactivateMenu()
{
Time.timeScale = 1;
AudioListener.pause = false;
pauseMenuUI.SetActive(false);
Player.GetComponent().enabled = true;
Player.GetComponent().enabled = true;
Cursor.lockState = CursorLockMode.Locked;
Cursor.visible = false;
}
public void ExitOut()
{
isPaused = (false);
SceneManager.LoadScene(1);
Player.GetComponent().enabled = false;
Player.GetComponent().enabled = false;
Cursor.lockState = CursorLockMode.None;
Cursor.visible = true;
}
}