mehr sachen

This commit is contained in:
GodGodGod20081
2026-06-18 12:23:13 +02:00
parent 3d4e51309c
commit d3dc823c6e
7 changed files with 3276 additions and 3 deletions
+72
View File
@@ -0,0 +1,72 @@
using UnityEngine;
public class Door_Rotate : MonoBehaviour
{
[SerializeField] private float openAngle = 90f;
[SerializeField] private float rotationSpeed = 2f;
[SerializeField] private float interactionDistance = 5f;
[SerializeField] private Vector3 rotationOffset = Vector3.zero;
private float targetRotation = 0f;
private float currentRotation = 0f;
private bool isOpen = false;
private Camera playerCamera;
private Vector3 pivotPoint;
void Start()
{
playerCamera = Camera.main;
currentRotation = transform.localEulerAngles.y;
targetRotation = currentRotation;
// Calculate pivot point from rotation offset
pivotPoint = transform.position + rotationOffset;
}
void Update()
{
if (Input.GetKeyDown(KeyCode.E) && IsPlayerLooking())
{
ToggleDoor();
}
SmoothRotateDoor();
}
private void ToggleDoor()
{
isOpen = !isOpen;
targetRotation = isOpen ? currentRotation + openAngle : currentRotation - openAngle;
}
private void SmoothRotateDoor()
{
currentRotation = Mathf.Lerp(currentRotation, targetRotation, Time.deltaTime * rotationSpeed);
// Rotate around the pivot point
transform.RotateAround(pivotPoint, Vector3.up, (currentRotation - transform.localEulerAngles.y));
transform.localEulerAngles = new Vector3(
transform.localEulerAngles.x,
currentRotation,
transform.localEulerAngles.z
);
}
private bool IsPlayerLooking()
{
if (playerCamera == null) return false;
Ray ray = new Ray(playerCamera.transform.position, playerCamera.transform.forward);
float distanceToPlayer = Vector3.Distance(playerCamera.transform.position, transform.position);
if (distanceToPlayer > interactionDistance) return false;
if (Physics.Raycast(ray, out RaycastHit hit, interactionDistance))
{
return hit.collider.gameObject == gameObject;
}
return false;
}
}
+2
View File
@@ -0,0 +1,2 @@
fileFormatVersion: 2
guid: 06852f09d119f7647b099917df7e799a
+1 -1
View File
@@ -1,4 +1,4 @@
//Oliver
//Oliver&Morten
using UnityEngine;
using UnityEngine.UI;