Controlevents are now working
This commit is contained in:
@@ -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)
|
||||
|
||||
8
Assets/Scripts/Events.meta
Normal file
8
Assets/Scripts/Events.meta
Normal file
@@ -0,0 +1,8 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 200db5235a9d2ed2ebc3fe21cb9776bb
|
||||
folderAsset: yes
|
||||
DefaultImporter:
|
||||
externalObjects: {}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
17
Assets/Scripts/Events/ControlEvents.cs
Normal file
17
Assets/Scripts/Events/ControlEvents.cs
Normal file
@@ -0,0 +1,17 @@
|
||||
using UnityEngine;
|
||||
|
||||
public static class ControlEvents
|
||||
{
|
||||
public static event System.Action<float, float> OnLookingInput;
|
||||
public static event System.Action<Vector3> OnMovingInput;
|
||||
|
||||
public static void Look(float pitch, float yaw)
|
||||
{
|
||||
OnLookingInput?.Invoke(pitch, yaw);
|
||||
}
|
||||
|
||||
public static void Move(Vector3 force)
|
||||
{
|
||||
OnMovingInput?.Invoke(force);
|
||||
}
|
||||
}
|
||||
2
Assets/Scripts/Events/ControlEvents.cs.meta
Normal file
2
Assets/Scripts/Events/ControlEvents.cs.meta
Normal file
@@ -0,0 +1,2 @@
|
||||
fileFormatVersion: 2
|
||||
guid: f6f57f29eb0f62ddcbeda3faf4517459
|
||||
@@ -11,6 +11,16 @@ namespace Assets.Scripts.Player
|
||||
UIHandler uihandler;
|
||||
GameObject interact;
|
||||
|
||||
private void OnEnable()
|
||||
{
|
||||
ControlEvents.OnLookingInput += LookAround;
|
||||
}
|
||||
|
||||
private void OnDisable()
|
||||
{
|
||||
ControlEvents.OnLookingInput -= LookAround;
|
||||
}
|
||||
|
||||
// Start is called before the first frame update
|
||||
void Start()
|
||||
{
|
||||
@@ -43,7 +53,7 @@ namespace Assets.Scripts.Player
|
||||
return null;
|
||||
}
|
||||
|
||||
public void LookAround(float pitch)
|
||||
public void LookAround(float pitch, float yaw)
|
||||
{
|
||||
transform.localRotation = Quaternion.Euler(pitch, 0f, 0f);
|
||||
}
|
||||
|
||||
@@ -38,6 +38,14 @@ namespace Assets.Scripts.Player
|
||||
#if UNITY_EDITOR
|
||||
SceneHandler.switchGameToMenu();
|
||||
#endif
|
||||
ControlEvents.OnLookingInput += rotate;
|
||||
ControlEvents.OnMovingInput += move;
|
||||
}
|
||||
|
||||
private void OnDisable()
|
||||
{
|
||||
ControlEvents.OnLookingInput -= rotate;
|
||||
ControlEvents.OnMovingInput -= move;
|
||||
}
|
||||
|
||||
void Start()
|
||||
@@ -179,7 +187,7 @@ namespace Assets.Scripts.Player
|
||||
GameObject.Find("QuestLog").GetComponent<QuestLog>().updateQuests("explore", gameObject, 1);
|
||||
}
|
||||
|
||||
public void rotate(float yaw){
|
||||
public void rotate(float pitch, float yaw){
|
||||
transform.rotation = Quaternion.Euler(0f, yaw, 0f);
|
||||
}
|
||||
|
||||
|
||||
@@ -18,10 +18,10 @@ EditorUserSettings:
|
||||
value: 065551555651080c54570d2741715e1541154a79752925322f2c4965b7b0646d
|
||||
flags: 0
|
||||
RecentlyUsedSceneGuid-4:
|
||||
value: 5a5757560101590a5d0c0e24427b5d44434e4c7a7b7a23677f2b4565b7b5353a
|
||||
value: 56060d5e5301505e0f5a5a2344200944154e4128792a2763297b4a30b2e2363a
|
||||
flags: 0
|
||||
RecentlyUsedSceneGuid-5:
|
||||
value: 56060d5e5301505e0f5a5a2344200944154e4128792a2763297b4a30b2e2363a
|
||||
value: 5a5757560101590a5d0c0e24427b5d44434e4c7a7b7a23677f2b4565b7b5353a
|
||||
flags: 0
|
||||
RecentlyUsedScenePath-0:
|
||||
value: 22424703114646680e0b0227036c6c111b07142f1f2b233e2867083debf42d
|
||||
|
||||
Reference in New Issue
Block a user