From f86abb3997d2a7ef7d8d28b67df52b98a358a3aa Mon Sep 17 00:00:00 2001 From: Xaver Date: Thu, 19 Jun 2025 19:44:07 +0200 Subject: [PATCH] fix --- .../Assets/Scripts/Player/DialogManager.cs | 13 ---- .../Scripts/Player/PlayerInteraction.cs | 15 ++-- .../Assets/Scripts/Player/PlayerMovement.cs | 68 ++++++++++--------- 3 files changed, 45 insertions(+), 51 deletions(-) diff --git a/blueberryPeak/Assets/Scripts/Player/DialogManager.cs b/blueberryPeak/Assets/Scripts/Player/DialogManager.cs index ee986d0..ba114ad 100644 --- a/blueberryPeak/Assets/Scripts/Player/DialogManager.cs +++ b/blueberryPeak/Assets/Scripts/Player/DialogManager.cs @@ -16,19 +16,6 @@ public class DialogManager : MonoBehaviour private Animator player; private Animator quester; - private void Awake() - { - if (Instance == null) - { - Instance = this; - DontDestroyOnLoad(gameObject); - } - else - { - Destroy(gameObject); // Ensure only one instance exists - } - } - private void Start() { dialogPanel.SetActive(false); // Hide on start diff --git a/blueberryPeak/Assets/Scripts/Player/PlayerInteraction.cs b/blueberryPeak/Assets/Scripts/Player/PlayerInteraction.cs index 8656443..7fcfded 100644 --- a/blueberryPeak/Assets/Scripts/Player/PlayerInteraction.cs +++ b/blueberryPeak/Assets/Scripts/Player/PlayerInteraction.cs @@ -10,12 +10,12 @@ public class PlayerInteraction : MonoBehaviour [SerializeField] private InputActionReference InteractAction; [SerializeField] private InputActionReference DialogAction; [SerializeField] private GameObject dialogManagerObject; - private List interactableObjects = new(); + [SerializeField] private List inventory = new(); + private readonly List interactableObjects = new(); private int blueberryCount; private int dialogIndex; private DialogManager dialogManager; - [SerializeField] private List inventory = new(); private GameObject speaker; @@ -72,6 +72,7 @@ public class PlayerInteraction : MonoBehaviour speaker = null; dialogManager.HideDialog(); } + dialogIndex++; } } @@ -127,12 +128,13 @@ public class PlayerInteraction : MonoBehaviour else { dialogManager.ShowDialog("" + dialog[dialogIndex].speaker + ": ", - dialog[dialogIndex].text, gameObject?.GetComponentInChildren(), - speaker?.GetComponentInChildren()); + dialog[dialogIndex].text, gameObject?.GetComponentInChildren(), + speaker?.GetComponentInChildren()); dialogIndex++; } } } + public Dialog[] GetDialog() { return dialog; @@ -142,6 +144,7 @@ public class PlayerInteraction : MonoBehaviour { dialog = savedDialog; } + public int GetBlueberryCount() { return blueberryCount; @@ -160,7 +163,7 @@ public class PlayerInteraction : MonoBehaviour 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) inventory.Add(Instantiate(reward)); else @@ -171,7 +174,7 @@ public class PlayerInteraction : MonoBehaviour public void RemoveFromInventory(InventoryItem reward) { 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) { inventory.Remove(item); diff --git a/blueberryPeak/Assets/Scripts/Player/PlayerMovement.cs b/blueberryPeak/Assets/Scripts/Player/PlayerMovement.cs index fbb0610..0fe244d 100644 --- a/blueberryPeak/Assets/Scripts/Player/PlayerMovement.cs +++ b/blueberryPeak/Assets/Scripts/Player/PlayerMovement.cs @@ -1,28 +1,31 @@ using UnityEngine; using UnityEngine.InputSystem; +using Event = AK.Wwise.Event; [RequireComponent(typeof(CharacterController))] public class PlayerMovement : MonoBehaviour { - [Header("Movement Settings")] - [SerializeField] private float movementSpeed = 5f; + [Header("Movement Settings")] [SerializeField] + private float movementSpeed = 5f; + [SerializeField] private float rotationSpeed = 200f; [SerializeField] private InputActionReference movement; [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; - [Header("Footstep Sound Settings")] - [SerializeField] private AK.Wwise.Event footstepEvent; - [SerializeField] private float footstepInterval = 0.5f; // seconds between footsteps - private float footstepTimer = 0f; + [Header("Footstep Sound Settings")] [SerializeField] + private Event footstepEvent; - private Vector3 inputDirection = Vector3.zero; - private CharacterController controller; + [SerializeField] private float footstepInterval = 0.5f; // seconds between footsteps public bool moveAllowed = true; + private CharacterController controller; + private float footstepTimer; - void Start() + private Vector3 inputDirection = Vector3.zero; + + private void Start() { controller = GetComponent(); @@ -31,41 +34,28 @@ public class PlayerMovement : MonoBehaviour movement.action.canceled += OnMovementStop; } - void OnMovement(InputAction.CallbackContext context) - { - if (moveAllowed) - { - Vector2 inputVector = context.ReadValue(); - inputDirection = new Vector3(inputVector.x, 0, inputVector.y); - } - } - - void OnMovementStop(InputAction.CallbackContext context) - { - inputDirection = Vector3.zero; - } - - void Update() + private void Update() { Cursor.lockState = CursorLockMode.Locked; - Vector3 cameraForward = cameraTransform.forward; - Vector3 cameraRight = cameraTransform.right; + var cameraForward = cameraTransform.forward; + var cameraRight = cameraTransform.right; cameraForward.y = 0; cameraRight.y = 0; cameraForward.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); _animator.SetFloat("Speed", move.magnitude); if (move.magnitude > 0.01f) { - Quaternion toRotation = Quaternion.LookRotation(move, Vector3.up); - transform.rotation = Quaternion.RotateTowards(transform.rotation, toRotation, rotationSpeed * Time.deltaTime); + var toRotation = Quaternion.LookRotation(move, Vector3.up); + transform.rotation = + Quaternion.RotateTowards(transform.rotation, toRotation, rotationSpeed * Time.deltaTime); // Footstep logic footstepTimer -= Time.deltaTime; @@ -81,7 +71,7 @@ public class PlayerMovement : MonoBehaviour } } - void LateUpdate() + private void LateUpdate() { if (cameraTransform != null) { @@ -89,4 +79,18 @@ public class PlayerMovement : MonoBehaviour cameraTransform.LookAt(transform.position); } } -} + + private void OnMovement(InputAction.CallbackContext context) + { + if (moveAllowed) + { + var inputVector = context.ReadValue(); + inputDirection = new Vector3(inputVector.x, 0, inputVector.y); + } + } + + private void OnMovementStop(InputAction.CallbackContext context) + { + inputDirection = Vector3.zero; + } +} \ No newline at end of file