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);
+128
View File
@@ -0,0 +1,128 @@
using System.Collections;
using UnityEngine;
public class GrappleGun : Tool
{
[Header("Grapple Gun Parameters")]
public float range;
public float hookStickTime;
public GameObject hook;
bool isMoving = false;
bool stuckInTarget = false;
private Vector3 hookBaseLocation;
private Transform hookParent;
private void Start()
{
hookBaseLocation = hook.transform.localPosition;
hookParent = hook.transform.parent;
}
IEnumerator GoToTarget(Vector3 target)
{
GameManager.Instance.GetPlayerController().SetCharacterControl(false);
isMoving = true;
Vector3 startPosition = hook.transform.position;
float elapsedTime = 0f;
while (elapsedTime < hookStickTime)
{
float t = elapsedTime / hookStickTime;
hook.transform.position = Vector3.Lerp(startPosition, target, t);
elapsedTime += Time.deltaTime;
yield return null;
}
// Ensure final position is exact
hook.transform.position = target;
hook.transform.parent = null;
isMoving = false;
stuckInTarget = true;
StartCoroutine(MovePlayerToTarget(target));
}
IEnumerator MovePlayerToTarget(Vector3 target)
{
Transform player = GameManager.Instance.GetPlayerController().transform;
Vector3 startPosition = player.position;
float elapsedTime = 0f;
while (elapsedTime < hookStickTime)
{
float t = elapsedTime / hookStickTime;
player.position = Vector3.Lerp(startPosition, target, t);
elapsedTime += Time.deltaTime;
yield return null;
}
// Ensure final position is exact
player.position = target;
stuckInTarget = false;
hook.transform.parent = hookParent;
hook.transform.localPosition = hookBaseLocation;
isMoving = false;
stuckInTarget = false;
GameManager.Instance.GetPlayerController().SetCharacterControl(true);
}
IEnumerator ShootAndMiss()
{
GameManager.Instance.GetPlayerController().SetCharacterControl(false);
isMoving = true;
// move to edge of range and don't stick anywhere
Vector3 startPosition = hook.transform.position;
Vector3 target = transform.position + (transform.forward * range);
float elapsedTime = 0f;
while (elapsedTime < hookStickTime)
{
float t = elapsedTime / hookStickTime;
hook.transform.position = Vector3.Lerp(startPosition, target, t);
elapsedTime += Time.deltaTime;
yield return null;
}
hook.transform.localPosition = hookBaseLocation;
isMoving = false;
stuckInTarget = false;
GameManager.Instance.GetPlayerController().SetCharacterControl(true);
}
public override void Use()
{
if (stuckInTarget || isMoving)
{
StopAllCoroutines();
hook.transform.parent = hookParent;
hook.transform.localPosition = hookBaseLocation;
isMoving = false;
stuckInTarget = false;
GameManager.Instance.GetPlayerController().SetCharacterControl(true);
}
else
{
RaycastHit hit;
if (Physics.Raycast(transform.position, transform.forward, out hit, range))
{
StartCoroutine(GoToTarget(hit.point));
}
else
{
StartCoroutine(ShootAndMiss());
}
}
}
public override void UseAlt()
{
throw new System.NotImplementedException();
}
}
+2
View File
@@ -0,0 +1,2 @@
fileFormatVersion: 2
guid: 70102eddcaad3044d9ac0ec62519caad