Added pausing across all scenes and fixed any noticable bugs caused by pausing

This commit is contained in:
Gregory Campbell
2020-01-18 12:23:59 -05:00
parent 0380aab750
commit 4b2b676aae
12 changed files with 4917 additions and 45 deletions
+12 -5
View File
@@ -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 {
+80
View File
@@ -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");
}
}
+11
View File
@@ -0,0 +1,11 @@
fileFormatVersion: 2
guid: 0c6b30107c3524640ba48d3bc77c7126
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:
+5 -2
View File
@@ -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;