better cam + öine fix
This commit is contained in:
parent
b7d38dcbb9
commit
cb13d68831
3 changed files with 78 additions and 0 deletions
59
Assets/Scripts/CameraOrbit.cs
Normal file
59
Assets/Scripts/CameraOrbit.cs
Normal file
|
|
@ -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;
|
||||
}
|
||||
}
|
||||
2
Assets/Scripts/CameraOrbit.cs.meta
Normal file
2
Assets/Scripts/CameraOrbit.cs.meta
Normal file
|
|
@ -0,0 +1,2 @@
|
|||
fileFormatVersion: 2
|
||||
guid: 663151ee9debe374294b23f4aa357cf4
|
||||
|
|
@ -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
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue