This commit is contained in:
Xaver 2025-06-19 19:44:07 +02:00
parent f9daf36d1c
commit f86abb3997
3 changed files with 45 additions and 51 deletions

View File

@ -16,19 +16,6 @@ public class DialogManager : MonoBehaviour
private Animator player; private Animator player;
private Animator quester; private Animator quester;
private void Awake()
{
if (Instance == null)
{
Instance = this;
DontDestroyOnLoad(gameObject);
}
else
{
Destroy(gameObject); // Ensure only one instance exists
}
}
private void Start() private void Start()
{ {
dialogPanel.SetActive(false); // Hide on start dialogPanel.SetActive(false); // Hide on start

View File

@ -10,12 +10,12 @@ public class PlayerInteraction : MonoBehaviour
[SerializeField] private InputActionReference InteractAction; [SerializeField] private InputActionReference InteractAction;
[SerializeField] private InputActionReference DialogAction; [SerializeField] private InputActionReference DialogAction;
[SerializeField] private GameObject dialogManagerObject; [SerializeField] private GameObject dialogManagerObject;
private List<GameObject> interactableObjects = new(); [SerializeField] private List<InventoryItem> inventory = new();
private readonly List<GameObject> interactableObjects = new();
private int blueberryCount; private int blueberryCount;
private int dialogIndex; private int dialogIndex;
private DialogManager dialogManager; private DialogManager dialogManager;
[SerializeField] private List<InventoryItem> inventory = new();
private GameObject speaker; private GameObject speaker;
@ -72,6 +72,7 @@ public class PlayerInteraction : MonoBehaviour
speaker = null; speaker = null;
dialogManager.HideDialog(); dialogManager.HideDialog();
} }
dialogIndex++; dialogIndex++;
} }
} }
@ -133,6 +134,7 @@ public class PlayerInteraction : MonoBehaviour
} }
} }
} }
public Dialog[] GetDialog() public Dialog[] GetDialog()
{ {
return dialog; return dialog;
@ -142,6 +144,7 @@ public class PlayerInteraction : MonoBehaviour
{ {
dialog = savedDialog; dialog = savedDialog;
} }
public int GetBlueberryCount() public int GetBlueberryCount()
{ {
return blueberryCount; return blueberryCount;
@ -160,7 +163,7 @@ public class PlayerInteraction : MonoBehaviour
public void AddToInventory(InventoryItem reward) public void AddToInventory(InventoryItem reward)
{ {
InventoryItem item = inventory.Find(e => e.itemName == reward.itemName); var item = inventory.Find(e => e.itemName == reward.itemName);
if (item == null) if (item == null)
inventory.Add(Instantiate(reward)); inventory.Add(Instantiate(reward));
else else
@ -171,7 +174,7 @@ public class PlayerInteraction : MonoBehaviour
public void RemoveFromInventory(InventoryItem reward) public void RemoveFromInventory(InventoryItem reward)
{ {
Debug.Log("Attempting to remove " + reward.name + " from inventory."); Debug.Log("Attempting to remove " + reward.name + " from inventory.");
InventoryItem item = inventory.Find(e => e.itemName == reward.itemName); var item = inventory.Find(e => e.itemName == reward.itemName);
if (item != null) if (item != null)
{ {
inventory.Remove(item); inventory.Remove(item);

View File

@ -1,28 +1,31 @@
using UnityEngine; using UnityEngine;
using UnityEngine.InputSystem; using UnityEngine.InputSystem;
using Event = AK.Wwise.Event;
[RequireComponent(typeof(CharacterController))] [RequireComponent(typeof(CharacterController))]
public class PlayerMovement : MonoBehaviour public class PlayerMovement : MonoBehaviour
{ {
[Header("Movement Settings")] [Header("Movement Settings")] [SerializeField]
[SerializeField] private float movementSpeed = 5f; private float movementSpeed = 5f;
[SerializeField] private float rotationSpeed = 200f; [SerializeField] private float rotationSpeed = 200f;
[SerializeField] private InputActionReference movement; [SerializeField] private InputActionReference movement;
[SerializeField] private Transform cameraTransform; [SerializeField] private Transform cameraTransform;
[SerializeField] private Vector3 cameraOffset = new Vector3(0, 10, -10); [SerializeField] private Vector3 cameraOffset = new(0, 10, -10);
[SerializeField] private Animator _animator; [SerializeField] private Animator _animator;
[Header("Footstep Sound Settings")] [Header("Footstep Sound Settings")] [SerializeField]
[SerializeField] private AK.Wwise.Event footstepEvent; private Event footstepEvent;
[SerializeField] private float footstepInterval = 0.5f; // seconds between footsteps
private float footstepTimer = 0f;
private Vector3 inputDirection = Vector3.zero; [SerializeField] private float footstepInterval = 0.5f; // seconds between footsteps
private CharacterController controller;
public bool moveAllowed = true; public bool moveAllowed = true;
private CharacterController controller;
private float footstepTimer;
void Start() private Vector3 inputDirection = Vector3.zero;
private void Start()
{ {
controller = GetComponent<CharacterController>(); controller = GetComponent<CharacterController>();
@ -31,41 +34,28 @@ public class PlayerMovement : MonoBehaviour
movement.action.canceled += OnMovementStop; movement.action.canceled += OnMovementStop;
} }
void OnMovement(InputAction.CallbackContext context) private void Update()
{
if (moveAllowed)
{
Vector2 inputVector = context.ReadValue<Vector2>();
inputDirection = new Vector3(inputVector.x, 0, inputVector.y);
}
}
void OnMovementStop(InputAction.CallbackContext context)
{
inputDirection = Vector3.zero;
}
void Update()
{ {
Cursor.lockState = CursorLockMode.Locked; Cursor.lockState = CursorLockMode.Locked;
Vector3 cameraForward = cameraTransform.forward; var cameraForward = cameraTransform.forward;
Vector3 cameraRight = cameraTransform.right; var cameraRight = cameraTransform.right;
cameraForward.y = 0; cameraForward.y = 0;
cameraRight.y = 0; cameraRight.y = 0;
cameraForward.Normalize(); cameraForward.Normalize();
cameraRight.Normalize(); cameraRight.Normalize();
Vector3 move = (cameraForward * inputDirection.z + cameraRight * inputDirection.x).normalized * movementSpeed; var move = (cameraForward * inputDirection.z + cameraRight * inputDirection.x).normalized * movementSpeed;
controller.SimpleMove(move); controller.SimpleMove(move);
_animator.SetFloat("Speed", move.magnitude); _animator.SetFloat("Speed", move.magnitude);
if (move.magnitude > 0.01f) if (move.magnitude > 0.01f)
{ {
Quaternion toRotation = Quaternion.LookRotation(move, Vector3.up); var toRotation = Quaternion.LookRotation(move, Vector3.up);
transform.rotation = Quaternion.RotateTowards(transform.rotation, toRotation, rotationSpeed * Time.deltaTime); transform.rotation =
Quaternion.RotateTowards(transform.rotation, toRotation, rotationSpeed * Time.deltaTime);
// Footstep logic // Footstep logic
footstepTimer -= Time.deltaTime; footstepTimer -= Time.deltaTime;
@ -81,7 +71,7 @@ public class PlayerMovement : MonoBehaviour
} }
} }
void LateUpdate() private void LateUpdate()
{ {
if (cameraTransform != null) if (cameraTransform != null)
{ {
@ -89,4 +79,18 @@ public class PlayerMovement : MonoBehaviour
cameraTransform.LookAt(transform.position); cameraTransform.LookAt(transform.position);
} }
} }
private void OnMovement(InputAction.CallbackContext context)
{
if (moveAllowed)
{
var inputVector = context.ReadValue<Vector2>();
inputDirection = new Vector3(inputVector.x, 0, inputVector.y);
}
}
private void OnMovementStop(InputAction.CallbackContext context)
{
inputDirection = Vector3.zero;
}
} }