Добавляю машины и настраиваю их
This commit is contained in:
1 parent
1c106ea853
commit
a8238ab49e
363 files changed
+54820
-687
No files matched your search
@@ -0,0 +1,82 @@
|
||||
using UnityEngine;
|
||||
|
||||
public class CarPartMountZone : MonoBehaviour, IInteractable
|
||||
{
|
||||
private CarPart targetPart;
|
||||
private Collider zoneCollider;
|
||||
|
||||
public void Initialize(CarPart part)
|
||||
{
|
||||
targetPart = part;
|
||||
gameObject.layer = part.gameObject.layer;
|
||||
|
||||
// В точности копируем параметры оригинального коллайдера детали
|
||||
Collider sourceCollider = part.GetComponent<Collider>();
|
||||
|
||||
if (sourceCollider is BoxCollider sourceBox)
|
||||
{
|
||||
BoxCollider box = gameObject.AddComponent<BoxCollider>();
|
||||
box.center = sourceBox.center;
|
||||
box.size = sourceBox.size;
|
||||
box.isTrigger = true;
|
||||
zoneCollider = box;
|
||||
}
|
||||
else if (sourceCollider is MeshCollider sourceMesh)
|
||||
{
|
||||
MeshCollider meshCol = gameObject.AddComponent<MeshCollider>();
|
||||
meshCol.sharedMesh = sourceMesh.sharedMesh;
|
||||
meshCol.convex = true;
|
||||
meshCol.isTrigger = true;
|
||||
zoneCollider = meshCol;
|
||||
}
|
||||
else
|
||||
{
|
||||
// Универсальный запасной вариант
|
||||
SphereCollider sphere = gameObject.AddComponent<SphereCollider>();
|
||||
sphere.radius = 0.6f;
|
||||
sphere.isTrigger = true;
|
||||
zoneCollider = sphere;
|
||||
}
|
||||
}
|
||||
|
||||
public string GetPrompt()
|
||||
{
|
||||
PlayerHands hands = FindAnyObjectByType<PlayerHands>();
|
||||
|
||||
// Показываем надпись ТОЛЬКО если игрок держит именно эту деталь
|
||||
if (hands != null && hands.IsHolding && hands.CurrentPart == targetPart)
|
||||
{
|
||||
return $"Установить {targetPart.Data.partName} (E)";
|
||||
}
|
||||
|
||||
return string.Empty;
|
||||
}
|
||||
|
||||
public void Interact(GameObject interactor)
|
||||
{
|
||||
PlayerHands hands = interactor.GetComponent<PlayerHands>();
|
||||
if (hands == null) hands = interactor.GetComponentInParent<PlayerHands>();
|
||||
|
||||
if (hands != null && hands.IsHolding && hands.CurrentPart == targetPart)
|
||||
{
|
||||
hands.ClearHandAfterInstall();
|
||||
targetPart.Install();
|
||||
Destroy(gameObject); // Убираем зону после установки
|
||||
}
|
||||
}
|
||||
|
||||
// Рисует зеленый контур зоны в окне Scene во время игры
|
||||
private void OnDrawGizmos()
|
||||
{
|
||||
Gizmos.color = Color.green;
|
||||
if (zoneCollider is BoxCollider box)
|
||||
{
|
||||
Gizmos.matrix = transform.localToWorldMatrix;
|
||||
Gizmos.DrawWireCube(box.center, box.size);
|
||||
}
|
||||
else
|
||||
{
|
||||
Gizmos.DrawWireSphere(transform.position, 0.5f);
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user