Added pausing across all scenes and fixed any noticable bugs caused by pausing
This commit is contained in:
@@ -1,6 +1,7 @@
|
||||
using System.Collections;
|
||||
using System.Collections.Generic;
|
||||
using UnityEngine;
|
||||
using UnityEngine.SceneManagement;
|
||||
|
||||
public class CameraController : MonoBehaviour
|
||||
{
|
||||
@@ -21,15 +22,21 @@ public class CameraController : MonoBehaviour
|
||||
pivot.position = player.position;
|
||||
pivot.parent = null;
|
||||
|
||||
Cursor.visible = !Cursor.visible;
|
||||
Cursor.lockState = CursorLockMode.Locked;
|
||||
}
|
||||
|
||||
void LateUpdate(){
|
||||
float camX = Input.GetAxisRaw("Mouse X") * rotateSpeed;
|
||||
pivot.Rotate(0, camX, 0);
|
||||
|
||||
float camY = Input.GetAxisRaw("Mouse Y") * rotateSpeed;
|
||||
float camX = 0;
|
||||
float camY = 0;
|
||||
|
||||
if(!PauseMenu.GameIsPaused)
|
||||
{
|
||||
camX = Input.GetAxisRaw("Mouse X") * rotateSpeed;
|
||||
camY = Input.GetAxisRaw("Mouse Y") * rotateSpeed;
|
||||
}
|
||||
|
||||
pivot.Rotate(0, camX, 0);
|
||||
|
||||
if (invertY){
|
||||
pivot.Rotate(camY, 0, 0);
|
||||
} else {
|
||||
|
||||
@@ -0,0 +1,80 @@
|
||||
using System.Collections;
|
||||
using System.Collections.Generic;
|
||||
using UnityEngine;
|
||||
using UnityEngine.SceneManagement;
|
||||
|
||||
public class PauseMenu : MonoBehaviour
|
||||
{
|
||||
|
||||
public static bool GameIsPaused = false;
|
||||
|
||||
public GameObject pauseMenuUI;
|
||||
|
||||
// Start is called before the first frame update
|
||||
void Start()
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
// Update is called once per frame
|
||||
void Update()
|
||||
{
|
||||
|
||||
if(Input.GetButtonDown("Pause"))
|
||||
{
|
||||
if(GameIsPaused)
|
||||
{
|
||||
Resume();
|
||||
Cursor.visible = !Cursor.visible;
|
||||
Cursor.lockState = CursorLockMode.Locked;
|
||||
} else {
|
||||
Pause();
|
||||
Cursor.visible = Cursor.visible;
|
||||
Cursor.lockState = CursorLockMode.None;
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
public void Resume()
|
||||
{
|
||||
pauseMenuUI.SetActive(false);
|
||||
Time.timeScale = 1f;
|
||||
GameIsPaused = false;
|
||||
Cursor.visible = !Cursor.visible;
|
||||
Cursor.lockState = CursorLockMode.Locked;
|
||||
}
|
||||
|
||||
void Pause()
|
||||
{
|
||||
pauseMenuUI.SetActive(true);
|
||||
Time.timeScale = 0f;
|
||||
GameIsPaused = true;
|
||||
Cursor.visible = Cursor.visible;
|
||||
Cursor.lockState = CursorLockMode.None;
|
||||
}
|
||||
|
||||
public void LoadHubWorld()
|
||||
{
|
||||
Time.timeScale = 1f;
|
||||
GameIsPaused = false;
|
||||
SceneManager.LoadScene("Hub World", LoadSceneMode.Single);
|
||||
Cursor.visible = !Cursor.visible;
|
||||
Cursor.lockState = CursorLockMode.Locked;
|
||||
}
|
||||
|
||||
public void LoadMenu()
|
||||
{
|
||||
Time.timeScale = 1f;
|
||||
GameIsPaused = false;
|
||||
SceneManager.LoadScene("Main Menu", LoadSceneMode.Single);
|
||||
}
|
||||
|
||||
public void Quit()
|
||||
{
|
||||
|
||||
Application.Quit();
|
||||
Debug.Log("QUIT");
|
||||
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 0c6b30107c3524640ba48d3bc77c7126
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
@@ -60,6 +60,9 @@ public class PlayerController : MonoBehaviour
|
||||
capsuleHeight = capsule.height;
|
||||
maxSpeedStore = maxSpeed;
|
||||
accelerationStore = acceleration;
|
||||
|
||||
Cursor.visible = !Cursor.visible;
|
||||
Cursor.lockState = CursorLockMode.Locked;
|
||||
}
|
||||
|
||||
void OnControllerColliderHit(ControllerColliderHit hit)
|
||||
@@ -160,7 +163,7 @@ public class PlayerController : MonoBehaviour
|
||||
}
|
||||
}
|
||||
|
||||
if(Input.GetButton("Crouch") || Input.GetAxis("Crouch") == 1.0f)
|
||||
if((Input.GetButton("Crouch") || Input.GetAxis("Crouch") == 1.0f) && !PauseMenu.GameIsPaused)
|
||||
{
|
||||
|
||||
characterController.height /= 2;
|
||||
@@ -209,7 +212,7 @@ public class PlayerController : MonoBehaviour
|
||||
} else {
|
||||
slideTime = Time.time;
|
||||
|
||||
if(Input.GetButton("Crouch") || Input.GetAxis("Crouch") == 1.0f)
|
||||
if((Input.GetButton("Crouch") || Input.GetAxis("Crouch") == 1.0f) && !PauseMenu.GameIsPaused)
|
||||
{
|
||||
|
||||
characterController.height /= 2;
|
||||
|
||||
Reference in New Issue
Block a user