Controlevents are now working

This commit is contained in:
finnchen123
2026-01-25 13:23:03 +01:00
parent 93f02eee13
commit b657de5ea0
7 changed files with 75 additions and 33 deletions

View File

@@ -7,6 +7,7 @@ using UnityEngine.InputSystem;
using UnityEngine.UI;
using Assets.Scripts.Player;
using Assets.Scripts.InteractableObjects;
using System;
public class Controls : MonoBehaviour
{
@@ -55,34 +56,9 @@ public class Controls : MonoBehaviour
{
playerInput.SwitchCurrentActionMap("Menu");
}
if (!player.GetComponent<PlayerGameObject>().takeDamage(0))
if (uihandler.canPlayerMove())
{
if (!uihandler.isPlayerInFight())
{
if (uihandler.canPlayerRotate())
{
lookInput = Mouse.current.delta.ReadValue();
Vector2 targetRotation = lookInput * sensitivityMouse * Time.deltaTime;
currentRotation = Vector2.SmoothDamp(
currentRotation,
targetRotation,
ref rotationVelocity,
smoothTime
);
yaw += currentRotation.x;
pitch -= currentRotation.y;
pitch = Mathf.Clamp(pitch, minPitch, maxPitch);
// Apply rotations
transform.rotation = Quaternion.Euler(0f, yaw, 0f);
playerCam.GetComponent<PlayerCamera>().LookAround(pitch);
player.GetComponent<PlayerGameObject>().rotate(yaw);
}
if (uihandler.canPlayerMove())
{
player.GetComponent<PlayerGameObject>().move(input);
}
}
ControlEvents.Move(input);
}
}
@@ -105,9 +81,30 @@ public class Controls : MonoBehaviour
}
}
public void OnLooking(InputValue value)
public void LateUpdate()
{
//lookInput = value.Get<Vector2>();
//Stop execution if player is not created yet or if player is dead
if (player.GetComponent<PlayerGameObject>().takeDamage(0)) return;
//Stop execution if player is in fight
if (uihandler.isPlayerInFight()) return;
if (uihandler.canPlayerRotate())
{
lookInput = Mouse.current.delta.ReadValue();
Vector2 targetRotation = lookInput * sensitivityMouse * Time.deltaTime;
currentRotation = Vector2.SmoothDamp(
currentRotation,
targetRotation,
ref rotationVelocity,
smoothTime
);
yaw += currentRotation.x;
pitch -= currentRotation.y;
pitch = Mathf.Clamp(pitch, minPitch, maxPitch);
ControlEvents.Look(pitch, yaw);
}
}
public void OnMovement(InputValue value)