Add items, Pickup logic works

This commit is contained in:
2024-10-17 01:22:54 +02:00
parent ec487096bf
commit f594bdf112
72 changed files with 7258 additions and 918 deletions

View File

@@ -5,16 +5,29 @@ using UnityEngine.InputSystem;
public class PlayerController : BasicCharacter {
public static PlayerController Instance { get; private set; }
[SerializeField] private InputActionAsset _inputAsset;
[SerializeField] private InputActionReference _movementAction;
[SerializeField] private InputActionReference _interactionAction;
[SerializeField] private Transform _holderTransform;
private Object _object;
protected override void Awake() {
base.Awake();
if (_inputAsset == null) return;
if (_inputAsset == null || _interactionAction == null) return;
_interactionAction.action.performed += ctx => _interactionBehaviour.Interact();
if (Instance != null) {
Debug.LogError("What? 2 players crazy!!!");
}
Instance = this;
}
private void OnEnable() {
if (_inputAsset == null) return;
if (_inputAsset == null || _interactionAction == null) return;
_inputAsset.Enable();
}
@@ -25,15 +38,48 @@ public class PlayerController : BasicCharacter {
private void Update() {
HandleMovementInput();
HandleInteraction();
}
private void HandleInteraction() {
if (_movementBehaviour == null)
return;
if(_interactionBehaviour == null)
return;
_interactionBehaviour.HandleInteraction();
}
void HandleMovementInput() {
if (_movementBehaviour == null ||
_movementAction == null)
return;
//movement
float movementInput = _movementAction.action.ReadValue<float>();
Vector3 movement = movementInput * Vector3.right;
_movementBehaviour.DesiredMovementDirection = movement;
Vector2 movementInput = _movementAction.action.ReadValue<Vector2>();
Vector3 desiredDirection = new Vector3(movementInput.x, 0, movementInput.y);
_movementBehaviour.desiredMovementDirection = desiredDirection;
_movementBehaviour.desiredLookDirection = desiredDirection;
}
//TODO: ask teacher if this is fine
public Transform GetHolderTransform() {
return _holderTransform;
}
public void SetObject(Object obj) {
_object = obj;
}
public Object GetObject() {
return _object;
}
public void ClearObject() {
_object = null;
}
public bool HasObject() {
return _object != null;
}
}