From f831f7e310901e335229fcd293cc49fb46a22571 Mon Sep 17 00:00:00 2001 From: Jan Breitkreuz Date: Fri, 14 Jun 2024 10:30:48 +0200 Subject: [PATCH] Spieler kann sich umgucken + Cursor ist gelockt --- Plunderblock/Assets/Scenes/JanScene.unity | 4 +-- .../PlayerScripts/PlayerMoveScript.cs | 29 +++++++++++++++++-- 2 files changed, 29 insertions(+), 4 deletions(-) diff --git a/Plunderblock/Assets/Scenes/JanScene.unity b/Plunderblock/Assets/Scenes/JanScene.unity index 3c317ed..1135c16 100644 --- a/Plunderblock/Assets/Scenes/JanScene.unity +++ b/Plunderblock/Assets/Scenes/JanScene.unity @@ -658,8 +658,8 @@ MonoBehaviour: m_Name: m_EditorClassIdentifier: speed: 2 - xSensitivity: 200 - ySensitivity: 200 + xSensitivity: 250 + ySensitivity: 250 cam: {fileID: 1132902784} --- !u!1 &1771553239 GameObject: diff --git a/Plunderblock/Assets/Scripts/ScriptsJan/PlayerScripts/PlayerMoveScript.cs b/Plunderblock/Assets/Scripts/ScriptsJan/PlayerScripts/PlayerMoveScript.cs index f042554..7aec3ca 100644 --- a/Plunderblock/Assets/Scripts/ScriptsJan/PlayerScripts/PlayerMoveScript.cs +++ b/Plunderblock/Assets/Scripts/ScriptsJan/PlayerScripts/PlayerMoveScript.cs @@ -1,5 +1,6 @@ using System.Collections; using System.Collections.Generic; +using System.Threading; using UnityEngine; public class PlayerMoveScript : MonoBehaviour @@ -11,9 +12,13 @@ public class PlayerMoveScript : MonoBehaviour private Rigidbody rb; public Camera cam; + private bool cursorIsLocked; + void Start() { rb = GetComponent(); + Cursor.lockState = CursorLockMode.Locked; + cursorIsLocked = true; } // Update is called once per frame @@ -35,6 +40,8 @@ public class PlayerMoveScript : MonoBehaviour look(); + lockCursor(); + } public void look() @@ -47,7 +54,25 @@ public class PlayerMoveScript : MonoBehaviour float newDirX = currentRotation.y + xMouseMovement; float newDirY = currentRotation.x - yMouseMovement; - cam.transform.rotation = Quaternion.Euler(0, newDirX, 0); - transform.rotation = Quaternion.Euler(newDirY, 0, 0); + cam.transform.localRotation = Quaternion.Euler(newDirY, 0, 0); + transform.rotation = Quaternion.Euler(0, newDirX, 0); + } + + public void lockCursor() + { + if (Input.GetKeyDown(KeyCode.Escape)) + { + if(!cursorIsLocked) + { + Cursor.lockState = CursorLockMode.Locked; + cursorIsLocked = true; + } + else + { + Cursor.lockState = CursorLockMode.None; + cursorIsLocked = false; + } + + } } }