Inpût Àctións

This commit is contained in:
Simon Lübeß
2024-04-07 00:58:57 +02:00
parent 3bdf7231e3
commit 029ca69924
9 changed files with 490 additions and 34 deletions

View File

@ -5,6 +5,7 @@ using Interaction;
using UnityEngine;
using UnityEngine.Events;
using UnityEngine.EventSystems;
using UnityEngine.InputSystem;
using UnityEngine.Serialization;
using Utility;
@ -64,7 +65,6 @@ public class Character : MonoBehaviour
{
grounded = Physics.Raycast(transform.position, Vector3.down, playerHeight * 0.5f + 0.2f, whatIsGround);
MyInput();
SpeedControl();
transform.rotation = Quaternion.RotateTowards(transform.rotation, _targetRotation, turningRate * Time.deltaTime);
@ -117,35 +117,41 @@ public class Character : MonoBehaviour
MovePlayer();
}
private void MyInput()
public void DoMove(InputAction.CallbackContext context)
{
horizontalInput = Input.GetAxisRaw("Horizontal");
verticalInput = Input.GetAxisRaw("Vertical");
Vector2 movement = context.ReadValue<Vector2>();
horizontalInput = movement.x;
verticalInput = movement.y;
if(horizontalInput != 0f || verticalInput != 0f)
{
_targetRotation = Quaternion.Euler(new Vector3(0f, Mathf.Atan2(horizontalInput, verticalInput) * Mathf.Rad2Deg, 0f));
}
}
public void DoJump(InputAction.CallbackContext context)
{
if (!context.performed || !readyToJump || !grounded)
return;
if (Input.GetKey(jumpKey) && readyToJump && grounded)
{
readyToJump = false;
Jump();
Jump();
Invoke(nameof(ResetJump), jumpCooldown);
}
Invoke(nameof(ResetJump), jumpCooldown);
}
if (Input.GetKeyDown(KeyCode.G))
{
PickupItem(null);
}
public void DoDropItem(InputAction.CallbackContext context)
{
if (!context.performed)
return;
PickupItem(null);
}
private void MovePlayer()
{
moveDirection = new Vector3(0, 0, verticalInput) + new Vector3(horizontalInput, 0, 0);
rb.AddForce(moveDirection.normalized * moveSpeed * 10f, ForceMode.Force);
}
@ -175,8 +181,12 @@ public class Character : MonoBehaviour
public void GiveItemTo(Developer developer)
{
Debug.Log($"Gebe {_carriedInteractible.Name} an {developer.Name}");
Interactible item = _carriedInteractible;
PickupItem(null);
Destroy(item.gameObject);
}
public void SayItsImpossible()