Есть система снятия навесного с авто. Надо дорабатывать. Машины все добавлены
This commit is contained in:
1 parent
a8238ab49e
commit
3e13180e34
15 files changed
+106236
-141
No files matched your search
@@ -1,14 +1,14 @@
|
||||
using System.Collections;
|
||||
using UnityEngine;
|
||||
|
||||
[RequireComponent(typeof(CarPartInteractable))]
|
||||
[RequireComponent(typeof(CarPart))]
|
||||
public class CarPartAnimator : MonoBehaviour
|
||||
{
|
||||
[Header("Настройки открытия")]
|
||||
[SerializeField] private Vector3 openRotation; // Например: (0, 0, 60) для капота
|
||||
[SerializeField] private float speed = 5f;
|
||||
|
||||
private CarPartInteractable interactable;
|
||||
public bool IsOpen => isOpen;
|
||||
private Quaternion closedRot;
|
||||
private Quaternion openRot;
|
||||
private bool isOpen = false;
|
||||
@@ -16,27 +16,12 @@ public class CarPartAnimator : MonoBehaviour
|
||||
|
||||
private void Awake()
|
||||
{
|
||||
interactable = GetComponent<CarPartInteractable>();
|
||||
|
||||
// Запоминаем изначальное (закрытое) положение детали
|
||||
closedRot = transform.localRotation;
|
||||
// Конвертируем введенные углы Эйлера в Кватернион
|
||||
openRot = Quaternion.Euler(openRotation);
|
||||
openRot = closedRot * Quaternion.Euler(openRotation);
|
||||
}
|
||||
|
||||
// Подписываемся при включении объекта
|
||||
private void OnEnable()
|
||||
{
|
||||
interactable.OnInteract += TogglePart;
|
||||
}
|
||||
|
||||
// ОТПИСЫВАЕМСЯ при выключении/удалении (Критически важно!)
|
||||
private void OnDisable()
|
||||
{
|
||||
interactable.OnInteract -= TogglePart;
|
||||
}
|
||||
|
||||
private void TogglePart()
|
||||
public void TogglePart()
|
||||
{
|
||||
isOpen = !isOpen;
|
||||
|
||||
@@ -46,6 +31,13 @@ public class CarPartAnimator : MonoBehaviour
|
||||
|
||||
animationCoroutine = StartCoroutine(AnimatePart(isOpen ? openRot : closedRot));
|
||||
}
|
||||
|
||||
public void ResetToClosed()
|
||||
{
|
||||
isOpen = false;
|
||||
if (animationCoroutine != null) StopCoroutine(animationCoroutine);
|
||||
transform.localRotation = closedRot;
|
||||
}
|
||||
|
||||
private IEnumerator AnimatePart(Quaternion targetRot)
|
||||
{
|
||||
|
||||
@@ -1,18 +0,0 @@
|
||||
using UnityEngine;
|
||||
using System;
|
||||
|
||||
public class CarPartInteractable : MonoBehaviour, IInteractable
|
||||
{
|
||||
[SerializeField] private string promptMessage = "Открыть (E)";
|
||||
|
||||
// Чистое C# событие
|
||||
public event Action OnInteract;
|
||||
|
||||
public string GetPrompt() => promptMessage;
|
||||
|
||||
public void Interact(GameObject interactor)
|
||||
{
|
||||
// Вызываем событие, если на него кто-то подписан
|
||||
OnInteract?.Invoke();
|
||||
}
|
||||
}
|
||||
@@ -1,3 +0,0 @@
|
||||
fileFormatVersion: 2
|
||||
guid: b3e2d09be7614eb280964996788872ed
|
||||
timeCreated: 1789942997
|
||||
Reference in new issue
Block a user