add pause menu

This commit is contained in:
2026-04-15 20:47:08 -05:00
parent 77625e7ad5
commit 46ec37309d
13 changed files with 5980 additions and 8102 deletions
+5
View File
@@ -14,6 +14,7 @@ public class GameManager : MonoBehaviour
public PlayerManager PlayerManager { get; private set; }
public Inventory Inventory { get; private set; }
public Storybools Storybools { get; private set; }
public PauseMenu PauseMenu { get; private set; }
// Are we currently in a scene transition?
private bool isTransitioningScenes = false;
@@ -52,6 +53,10 @@ private void ReloadReferences()
Instance.DialogueManager = GetComponent<DialogueManager>();
Instance.DialogueManager.ReloadReferences();
Instance.PauseMenu = GameObject.FindWithTag("PauseMenu").GetComponent<PauseMenu>();
Instance.PauseMenu.ReloadReferences();
Instance.PauseMenu.gameObject.SetActive(false);
Instance.Inventory = GetComponent<Inventory>();
Instance.TimeManager = GetComponent<TimeManager>();
Instance.PlayerManager = GetComponent<PlayerManager>();
+38 -2
View File
@@ -1,4 +1,5 @@
using System.Collections;
using Unity.VisualScripting.Antlr3.Runtime;
using UnityEngine;
using static UnityEngine.GraphicsBuffer;
@@ -18,7 +19,9 @@ public class PlayerController : MonoBehaviour
private CameraController cameraController;
private Vector3 moveDir;
private bool hasControl = true; // set this to false if we want to stop reading player inputs
private bool canUseTools = true; // set this to false if we want to stop reading player tool use
private bool isSprinting = false;
private bool paused = false;
// Mathematical plane used to catch the raycast from camera to get direction for
// looking at the mouse
@@ -39,6 +42,27 @@ void Update()
moveDir = Vector3.zero;
groundPlane.distance = -DougBody.transform.position.y;
// TODO: Move input detection somewhere else
if (Input.GetKeyDown(KeyCode.Escape))
{
if (!paused)
{
Time.timeScale = 0;
canUseTools = false;
hasControl = false;
GameManager.Instance.PauseMenu.gameObject.SetActive(true);
}
else
{
Time.timeScale = 1;
canUseTools = true;
hasControl = true;
GameManager.Instance.PauseMenu.gameObject.SetActive(false);
}
paused = !paused;
}
if (hasControl)
{
if (!tools[GameManager.Instance.PlayerManager.CurrentToolIndex].inUse)
@@ -47,7 +71,7 @@ void Update()
TryInteract();
}
ToolUseDetector();
CheckWeaponChange();
ApplyWalk();
// TODO: This is just for testing, remove or clean up if used
@@ -63,7 +87,11 @@ void Update()
}
}
CheckWeaponChange();
if (canUseTools)
{
ToolUseDetector();
}
CheckSprint();
ApplyGravity();
DoMovement();
@@ -257,6 +285,14 @@ public void SetCharacterControl(bool hasControl)
this.hasControl = hasControl;
}
/// <summary>
/// Sets the character's "canUseTools" bool. Tool use input is ignored when false
/// </summary>
public void SetCharacterCanUseTools(bool canUseTools)
{
this.canUseTools = canUseTools;
}
/// <summary>
/// Gets the character's "hasControl" bool. All input is ignored when false
/// </summary>
+13
View File
@@ -41,6 +41,19 @@ public static void Save()
File.WriteAllText(SaveFileName(), JsonUtility.ToJson(_saveData, true));
}
public static void ClearSave()
{
try
{
File.Delete(SaveFileName());
Debug.Log("File deleted successfully. Stop and restart player.");
}
catch (FileNotFoundException)
{
// file doesn't exist, don't need to do anything
}
}
private static void HandleSaveData()
{
GameManager.Instance.SaveStoryBools(ref _saveData.StoryboolData);