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 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

View File

@ -10,12 +10,12 @@ public class PlayerInteraction : MonoBehaviour
[SerializeField] private InputActionReference InteractAction;
[SerializeField] private InputActionReference DialogAction;
[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 dialogIndex;
private DialogManager dialogManager;
[SerializeField] private List<InventoryItem> 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("<b>" + dialog[dialogIndex].speaker + "</b>: ",
dialog[dialogIndex].text, gameObject?.GetComponentInChildren<Animator>(),
speaker?.GetComponentInChildren<Animator>());
dialog[dialogIndex].text, gameObject?.GetComponentInChildren<Animator>(),
speaker?.GetComponentInChildren<Animator>());
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);

View File

@ -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<CharacterController>();
@ -31,41 +34,28 @@ public class PlayerMovement : MonoBehaviour
movement.action.canceled += OnMovementStop;
}
void OnMovement(InputAction.CallbackContext context)
{
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()
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<Vector2>();
inputDirection = new Vector3(inputVector.x, 0, inputVector.y);
}
}
private void OnMovementStop(InputAction.CallbackContext context)
{
inputDirection = Vector3.zero;
}
}