Первый коммит с LFS.
This commit is contained in:
1 parent
4fcb1e2f24
commit
179816dc4b
5084 files changed
+3714098
-1
No files matched your search
@@ -0,0 +1,93 @@
|
||||
using UnityEngine;
|
||||
using System.Collections;
|
||||
|
||||
public class DoorController : MonoBehaviour, IInteractable
|
||||
{
|
||||
[Header("Settings")]
|
||||
[SerializeField] private float openAngle = 90f;
|
||||
[SerializeField] private float smoothSpeed = 2f;
|
||||
[SerializeField] private bool isLocked = false;
|
||||
|
||||
[Header("Key Settings")]
|
||||
[SerializeField] private ItemData keyRequired;
|
||||
|
||||
private bool _isOpen = false;
|
||||
private Quaternion _closedRotation;
|
||||
private Quaternion _openRotation;
|
||||
private Coroutine _animationCoroutine;
|
||||
|
||||
private void Start()
|
||||
{
|
||||
_closedRotation = transform.localRotation;
|
||||
_openRotation = _closedRotation * Quaternion.Euler(0, openAngle, 0);
|
||||
}
|
||||
|
||||
public void Interact()
|
||||
{
|
||||
if (_isOpen)
|
||||
{
|
||||
Close();
|
||||
}
|
||||
else
|
||||
{
|
||||
TryOpen();
|
||||
}
|
||||
}
|
||||
|
||||
public string GetDescription()
|
||||
{
|
||||
if (isLocked) return "Заперто (Нужен ключ)";
|
||||
return _isOpen ? "Закрыть" : "Открыть";
|
||||
}
|
||||
|
||||
private void TryOpen()
|
||||
{
|
||||
if (isLocked)
|
||||
{
|
||||
if (keyRequired != null && InventorySystem.Instance.HasItem(keyRequired))
|
||||
{
|
||||
Debug.Log("Ключ подошел! Дверь открыта.");
|
||||
isLocked = false;
|
||||
Open();
|
||||
}
|
||||
else
|
||||
{
|
||||
Debug.Log("Нужен ключ!");
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
Open();
|
||||
}
|
||||
}
|
||||
|
||||
private void Open()
|
||||
{
|
||||
_isOpen = true;
|
||||
StopAnimation();
|
||||
_animationCoroutine = StartCoroutine(AnimateDoor(_openRotation));
|
||||
}
|
||||
|
||||
private void Close()
|
||||
{
|
||||
_isOpen = false;
|
||||
StopAnimation();
|
||||
_animationCoroutine = StartCoroutine(AnimateDoor(_closedRotation));
|
||||
}
|
||||
|
||||
private void StopAnimation()
|
||||
{
|
||||
if (_animationCoroutine != null) StopCoroutine(_animationCoroutine);
|
||||
}
|
||||
|
||||
// Универсальная корутина для плавного вращения
|
||||
private IEnumerator AnimateDoor(Quaternion targetRotation)
|
||||
{
|
||||
while (Quaternion.Angle(transform.localRotation, targetRotation) > 0.1f)
|
||||
{
|
||||
transform.localRotation = Quaternion.Slerp(transform.localRotation, targetRotation, Time.deltaTime * smoothSpeed);
|
||||
yield return null;
|
||||
}
|
||||
transform.localRotation = targetRotation;
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user