So i created the pause menu by looking at a video and modified it so it could be useful whit UFPS,
so i did it and i dont get an error but here is the problem.
using UnityEngine;
using System.Collections;
using UnityStandardAssets.Characters.FirstPerson;
public class PauseGame : MonoBehaviour
{
public Transform canvas;
public Transform pauseMenu;
public Transform optionsMenu;
public Transform controlsMenu;
public Transform Player;
SaveGame SaveGame;
// Update is called once per frame
void Update() {
if (Input.GetKeyDown(KeyCode.Escape))
{
Pause();
}
}
public void Pause()
{
if (canvas.gameObject.activeInHierarchy == false)
{
if (pauseMenu.gameObject.activeInHierarchy == false)
{
pauseMenu.gameObject.SetActive(true);
optionsMenu.gameObject.SetActive(false);
controlsMenu.gameObject.SetActive(false);
}
Player.GetComponent<vp_FPInput>().enabled = false;
Player.GetComponent<vp_FPController>().enabled = false;
Player.GetComponent<vp_SimpleHUD>().enabled = false;
Cursor.visible = true;
canvas.gameObject.SetActive(true);
Time.timeScale = 0;
SaveGame = gameObject.GetComponent();
SaveGame.SaveGameSettings(false);
}
else
{
Player.GetComponent<vp_FPController>().enabled = true;
Player.GetComponent<vp_SimpleHUD>().enabled = true;
Player.GetComponent<vp_FPInput>().enabled = true;
Cursor.visible = false;
canvas.gameObject.SetActive(false);
Time.timeScale = 1;
}
}
public void ControlsMenu(bool Open)
{
if(Open)
{
controlsMenu.gameObject.SetActive(true);
pauseMenu.gameObject.SetActive(false);
}
if (!Open)
{
controlsMenu.gameObject.SetActive(false);
pauseMenu.gameObject.SetActive(true);
}
}
public void OptionsMenu(bool Open)
{
if (Open)
{
optionsMenu.gameObject.SetActive(true);
pauseMenu.gameObject.SetActive(false);
}
if (!Open)
{
optionsMenu.gameObject.SetActive(false);
pauseMenu.gameObject.SetActive(true);
}
}
}
so when i am pressing ESC everything works just fine but then when i press ESC or resume button again
i come to the Game but i cant move because the VP_FPInput is off but i did it so when
i am in play mode the VP_FPinput should be active. Please help me.
The one who gives me the answer, please write the name down and I’ll credit you on the start menu in the bottom left corner whit your name… Hope I’ll get some answers from smart people.
Pausing the UFPS player is more complicated than just disabling its components. The code below is adapted from the Dialogue System for Unity’s UFPS Support package. When you want to show your pause menu, call the Freeze() method to freeze the UFPS player. When you close the pause menu, call Unfreeze().
[Tooltip("When the scene starts, lock the cursor to enable mouse look without having to click in the window first")]
public bool lockCursorOnStart = true;
// If you don't assign these properties, the Awake() method will automatically assign them.
public vp_FPController fpController = null;
public vp_FPCamera fpCamera = null;
public vp_FPPlayerEventHandler fpPlayerEventHandler = null;
public vp_FPInput fpInput = null;
public vp_SimpleHUD fpHUD = null;
public MonoBehaviour fpCrosshair = null;
private bool wasCrosshairVisible;
void Awake()
{
if (fpController == null) fpController = GetComponentInChildren<vp_FPController>();
if (fpCamera == null) fpCamera = GetComponentInChildren<vp_FPCamera>();
if (fpPlayerEventHandler == null) fpPlayerEventHandler = GetComponentInChildren<vp_FPPlayerEventHandler>();
if (fpInput == null) fpInput = GetComponentInChildren<vp_FPInput>();
if (fpHUD == null) fpHUD = GetComponentInChildren<vp_SimpleHUD>();
if (fpCrosshair == null) fpCrosshair = GetComponentInChildren<vp_SimpleCrosshair>();
}
IEnumerator Start()
{
yield return null;
if (lockCursorOnStart) vp_Utility.LockCursor = true;
}
/// <summary>
/// Freeze the UFPS player (i.e., gameplay) and show the cursor.
/// </summary>
public void Freeze()
{
wasCrosshairVisible = (fpCrosshair != null) && fpCrosshair.enabled;
if (fpCrosshair != null) fpCrosshair.enabled = false;
if (fpController != null) fpController.Stop();
if (fpPlayerEventHandler != null)
{
fpPlayerEventHandler.Attack.TryStop();
fpPlayerEventHandler.InputAllowGameplay.Set(false);
}
if (fpCamera != null) fpCamera.SetState("Freeze", true);
if (fpInput != null) fpInput.MouseCursorForced = true;
if (hideHUD && (fpHUD != null)) fpHUD.enabled = false;
if (disableInputOnFreeze && fpInput != null) fpInput.enabled = false;
StartCoroutine(ShowCursorAfterOneFrame());
}
/// <summary>
/// Unfreeze the UFPS player (i.e. gameplay) and restore the previous cursor state.
/// </summary>
public void Unfreeze()
{
if (fpInput != null) fpInput.MouseCursorForced = false;
if (disableInputOnFreeze && fpInput != null) fpInput.enabled = true;
if ((fpCrosshair != null) && wasCrosshairVisible) fpCrosshair.enabled = true;
if (fpPlayerEventHandler != null) StartCoroutine(AllowInputAfterDelay());
if (fpCamera != null) fpCamera.SetState("Freeze", false);
if (hideHUD && (fpHUD != null)) fpHUD.enabled = true;
vp_Utility.LockCursor = true;
}
private IEnumerator AllowInputAfterDelay()
{
yield return new WaitForSeconds(0.2f);
fpPlayerEventHandler.InputAllowGameplay.Set(true);
}
/// <summary>
/// Shows the cursor after one frame. We wait one frame to allow UFPS to do any closeout
/// that might try to regain cursor control.
/// </summary>
private IEnumerator ShowCursorAfterOneFrame()
{
yield return null;
vp_Utility.LockCursor = false;
}