From cb13d688314cde941c3eec63889e6c3b2765e2f5 Mon Sep 17 00:00:00 2001 From: Leinadix <79761215+Leinadix@users.noreply.github.com> Date: Tue, 16 Sep 2025 13:04:05 +0200 Subject: [PATCH] =?UTF-8?q?better=20cam=20+=20=C3=B6ine=20fix?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- Assets/Scripts/CameraOrbit.cs | 59 ++++++++++++++++++++++++++++++ Assets/Scripts/CameraOrbit.cs.meta | 2 + Assets/Scripts/GameManager.cs | 17 +++++++++ 3 files changed, 78 insertions(+) create mode 100644 Assets/Scripts/CameraOrbit.cs create mode 100644 Assets/Scripts/CameraOrbit.cs.meta diff --git a/Assets/Scripts/CameraOrbit.cs b/Assets/Scripts/CameraOrbit.cs new file mode 100644 index 0000000..0098ca2 --- /dev/null +++ b/Assets/Scripts/CameraOrbit.cs @@ -0,0 +1,59 @@ +using UnityEngine; + +public class CameraOrbit : MonoBehaviour +{ + [Header("Target Settings")] + public Transform target; // Das Objekt, um das sich die Kamera drehen soll + public float distance = 5.0f; // Abstand zur Kamera + + [Header("Rotation Settings")] + public float xSpeed = 120.0f; // Geschwindigkeit für horizontale Drehung + public float ySpeed = 120.0f; // Geschwindigkeit für vertikale Drehung + public float yMinLimit = -20f; // Min. vertikaler Winkel + public float yMaxLimit = 80f; // Max. vertikaler Winkel + + private float x = 0.0f; + private float y = 0.0f; + + void Start() + { + if (target == null) + { + Debug.LogWarning("Kein Target gesetzt! Bitte ein Objekt in 'target' zuweisen."); + enabled = false; + return; + } + + Vector3 angles = transform.eulerAngles; + x = angles.y; + y = angles.x; + + // Cursor frei beweglich lassen + Cursor.lockState = CursorLockMode.None; + Cursor.visible = true; + } + + void LateUpdate() + { + if (target == null) return; + + if (Input.GetMouseButton(1)) // Rechte Maustaste gedrückt + { + Cursor.lockState = CursorLockMode.Locked; + Cursor.visible = false; + x += Input.GetAxis("Mouse X") * xSpeed * Time.deltaTime; + y -= Input.GetAxis("Mouse Y") * ySpeed * Time.deltaTime; + y = Mathf.Clamp(y, yMinLimit, yMaxLimit); + } else + { + Cursor.lockState = CursorLockMode.None; + Cursor.visible = true; + } + + Quaternion rotation = Quaternion.Euler(y, x, 0); + Vector3 position = rotation * new Vector3(0.0f, 0.0f, -distance) + target.position; + + transform.rotation = rotation; + transform.position = position; + } +} \ No newline at end of file diff --git a/Assets/Scripts/CameraOrbit.cs.meta b/Assets/Scripts/CameraOrbit.cs.meta new file mode 100644 index 0000000..3bef1fe --- /dev/null +++ b/Assets/Scripts/CameraOrbit.cs.meta @@ -0,0 +1,2 @@ +fileFormatVersion: 2 +guid: 663151ee9debe374294b23f4aa357cf4 \ No newline at end of file diff --git a/Assets/Scripts/GameManager.cs b/Assets/Scripts/GameManager.cs index 89e3d2f..c49caf9 100644 --- a/Assets/Scripts/GameManager.cs +++ b/Assets/Scripts/GameManager.cs @@ -113,6 +113,23 @@ public class GameManager : MonoBehaviour } } } + + #if UNITY_EDITOR + void OnDrawGizmos() + { + if (connections == null) return; + + // Linien respektieren den Z-Buffer + Handles.zTest = UnityEngine.Rendering.CompareFunction.LessEqual; + + foreach (var con in connections) + { + if(!con.allowed) continue; + Handles.color = Color.red; + Handles.DrawLine(con.nodeA.transform.position, con.nodeB.transform.position); + } + } + #endif } #if UNITY_EDITOR