- Home /
When exiting pause menu, player wont move at all
using UnityEngine;
using System.Collections;
using UnityEngine.UI;
using UnityStandardAssets.Characters.FirstPerson;
using UnityStandardAssets.ImageEffects;
public class HDK_PauseManager : MonoBehaviour
{
public static bool GamePaused;
[Header("Main Variables")]
public GameObject PauseMenu;
public GameObject OptionsPanel;
GameObject Player;
public GameObject[] ToDisableGUI;
[Header("Mouse SFX")]
public AudioClip mouseHover;
public AudioClip mouseClick;
public AudioClip openCloseSound;
AudioSource sourceAudio;
public float mouseVolume;
GameObject LoadingPrefab;
void Start()
{
GamePaused = false;
Player = GameObject.Find("Player");
sourceAudio = GetComponent<AudioSource>();
LoadingPrefab = GameObject.Find("Player").GetComponent<GameSceneManager>()._loadingScreen;
}
void Awake()
{
Cursor.visible = false;
Cursor.lockState = CursorLockMode.Locked;
}
public void PlayHover()
{
sourceAudio.PlayOneShot(mouseHover, mouseVolume);
}
public void PlayClick()
{
sourceAudio.PlayOneShot(mouseClick, mouseVolume);
}
public void LoadScene(string sceneToLoad)
{
HDK_LoadingScreen.LoadScene(sceneToLoad, LoadingPrefab);
}
public void UnPause()
{
Player.GetComponentInChildren<BlurOptimized>().enabled = false;
Player.GetComponentInChildren<HDK_RaycastManager>().enabled = true;
Player.GetComponent<HDK_MouseZoom>().canZoom = true;
Player.GetComponentInChildren<HeadBobController>().enabled = true;
Player.GetComponentInChildren<SwayWeapon>().enabled = true;
Player.GetComponent<HDK_Stamina>().Busy(false);
Player.GetComponent<FirstPersonController>().enabled = true;
GamePaused = false;
PauseMenu.SetActive(false);
Cursor.visible = false;
Cursor.lockState = CursorLockMode.Locked;
sourceAudio.clip = openCloseSound;
sourceAudio.Play();
foreach (GameObject obj in ToDisableGUI)
{
obj.SetActive(true);
}
}
public void DoPause()
{
Player.GetComponentInChildren<BlurOptimized>().enabled = true;
Player.GetComponentInChildren<HDK_RaycastManager>().enabled = false;
Player.GetComponent<HDK_MouseZoom>().ZoomOut();
Player.GetComponentInChildren<SwayWeapon>().enabled = false;
Player.GetComponentInChildren<HeadBobController>().enabled = false;
Player.GetComponent<HDK_Stamina>().Busy(true);
Player.GetComponent<FirstPersonController>().enabled = false;
GamePaused = true;
PauseMenu.SetActive(true);
Cursor.visible = true;
Cursor.lockState = CursorLockMode.None;
sourceAudio.clip = openCloseSound;
sourceAudio.Play();
foreach (GameObject obj in ToDisableGUI)
{
obj.SetActive(false);
}
}
void Update()
{
bool examining = HDK_RaycastManager.ExaminingObject;
bool reading = HDK_RaycastManager.ReadingPaper;
bool security = HDK_RaycastManager.UsingSecurityCam;
bool inventory = HDK_InventoryManager.inventoryOpen;
if (!GamePaused && !examining && !reading && !security && !inventory)
{
if (Input.GetButtonDown("PauseMenu"))
{
DoPause();
}
}
else if (examining)
{
if(Input.GetButtonDown("PauseMenu"))
{
HDK_WeaponsManager wepMan = FindObjectOfType<HDK_WeaponsManager>();
if (wepMan.usingGun)
{
wepMan.currentGun.SetActive(true);
}
else if (wepMan.usingMelee)
{
wepMan.currentMelee.SetActive(true);
}
else if (wepMan.usingFlashlight)
{
Player.GetComponent<HDK_Flashlight>().ArmsAnims.SetActive(true);
}
Player.GetComponentInChildren<HDK_RaycastManager>().PutDownObject();
DoPause();
}
}
else if (reading)
{
if (Input.GetButtonDown("PauseMenu"))
{
Player.GetComponentInChildren<HDK_RaycastManager>().ClosePaper();
DoPause();
}
}
else if (security)
{
if (Input.GetButtonDown("PauseMenu"))
{
Player.GetComponentInChildren<HDK_RaycastManager>().CloseCam();
DoPause();
}
}
else if (inventory)
{
if (Input.GetButtonDown("PauseMenu"))
{
FindObjectOfType<HDK_InventoryManager>().CloseInventory();
DoPause();
}
}
else if (GamePaused)
{
if (Input.GetButtonDown("PauseMenu"))
{
FindObjectOfType<HDK_PauseManager>().UnPause();
Cursor.visible = false;
Cursor.lockState = CursorLockMode.Locked;
UnPause();
}
}
public void QuitGame()
{
Application.Quit();
}
}
That's the code for pause menu (not all of it, as rest isn't related to this). What I'm trying to do here, is that it would after pressing Escape aka PauseMenu key to allow player to look around with mouse. Right now if you press ESC to access pause menu, and then press ESC again, you cant turn head with mouse. You can move forward, sideways and back with WASD, but you cant use mouse to look around. It's like whole mouse would be disabled, that is if you don't press ESC again and press "Resume" button on PauseMenu.
But I would like to make it so that you can press either ESC again or Resume button and you would still have ability to look around with mouse. Hopefully you guys do understand what I mean. If not I will make a small video on Youtube what's happening.
AFAIK There's no event trigger for "onkeydown" or something like that which would help with this problem alot.
You are never setting HeadBobController to be back on What you have to do is add this line to UnPause(): Player.GetComponentInChildren<HeadBobController>().enabled = true;
It is already on UnPause() on 7th line
public void UnPause()
{
Player.GetComponentInChildren<BlurOptimized>().enabled = false;
Player.GetComponentInChildren<HD$$anonymous$$_Raycast$$anonymous$$anager>().enabled = true;
Player.GetComponent<HD$$anonymous$$_$$anonymous$$ouseZoom>().canZoom = true;
Player.GetComponentInChildren<HeadBobController>().enabled = true;
Player.GetComponentInChildren<SwayWeapon>().enabled = true;
Player.GetComponent<HD$$anonymous$$_Sta$$anonymous$$a>().Busy(false);
Player.GetComponent<FirstPersonController>().enabled = true;
GamePaused = false;
Pause$$anonymous$$enu.SetActive(false);
Cursor.visible = false;
Cursor.lockState = CursorLock$$anonymous$$ode.Locked;
sourceAudio.clip = openCloseSound;
sourceAudio.Play();
foreach (GameObject obj in ToDisableGUI)
{
obj.SetActive(true);
}
}
So yeah, it wont do anything (except causing problems) if I add it there second time :) Thanks anyways.
I did add Debug.Log("Escape pressed unpaused"); to UnPause() and it gets printed out when Escape is pushed, so it does notice that Escape is pressed. and to DoPause() Debug.Log("Escape pressed paused); and those do get print out without problem.
Your answer
Follow this Question
Related Questions
Multiple Cars not working 1 Answer
Distribute terrain in zones 3 Answers
Time.timeScale doesnt work with GUI? 0 Answers
GUIButton menu is in wrong place in built version of my game 0 Answers
pause screen problem 0 Answers