Снятие колес работает, покраска тоже более менее. Физика просто говно щяс
This commit is contained in:
1 parent
d4c84b10df
commit
2ce853999d
67 files changed
+155919
-1996
No files matched your search
@@ -3,19 +3,18 @@ using UnityEngine;
|
||||
public class VehicleInteraction : MonoBehaviour, IInteractable
|
||||
{
|
||||
[Header("Setup")]
|
||||
[SerializeField] private Transform exitPoint;
|
||||
[SerializeField] private Transform exitPoint;
|
||||
[SerializeField] private UIManager uiManager;
|
||||
|
||||
private CarOrbitCamera globalCarCamera; // Ссылка на глобальную камеру
|
||||
|
||||
private CarOrbitCamera globalCarCamera;
|
||||
private CarController carController;
|
||||
private GameObject playerInstance;
|
||||
public bool isPlayerInside = false;
|
||||
[HideInInspector] public bool isPlayerInside;
|
||||
|
||||
private void Awake()
|
||||
{
|
||||
carController = GetComponent<CarController>();
|
||||
|
||||
// Автоматически находим камеру на сцене, даже если она выключена
|
||||
carController = GetComponent<CarController>() ?? GetComponentInChildren<CarController>() ?? GetComponentInParent<CarController>();
|
||||
if (uiManager == null) uiManager = FindAnyObjectByType<UIManager>();
|
||||
globalCarCamera = FindAnyObjectByType<CarOrbitCamera>(FindObjectsInactive.Include);
|
||||
}
|
||||
|
||||
@@ -24,48 +23,50 @@ public class VehicleInteraction : MonoBehaviour, IInteractable
|
||||
if (!isPlayerInside) EnterVehicle(interactor);
|
||||
}
|
||||
|
||||
public string GetPrompt()
|
||||
{
|
||||
return "Сесть в машину (E)";
|
||||
}
|
||||
public string GetPrompt() => "[F] Сесть в машину";
|
||||
|
||||
private void EnterVehicle(GameObject player)
|
||||
{
|
||||
isPlayerInside = true;
|
||||
playerInstance = player;
|
||||
playerInstance.SetActive(false);
|
||||
|
||||
// Передаем этой машине фокус и включаем камеру
|
||||
|
||||
if (globalCarCamera != null)
|
||||
{
|
||||
globalCarCamera.SetTarget(transform);
|
||||
globalCarCamera.gameObject.SetActive(true);
|
||||
}
|
||||
|
||||
if (uiManager != null) uiManager.ToggleDashboard(true);
|
||||
|
||||
if (uiManager != null)
|
||||
{
|
||||
uiManager.HidePrompt();
|
||||
uiManager.ToggleDashboard(true);
|
||||
}
|
||||
}
|
||||
|
||||
private void ExitVehicle()
|
||||
{
|
||||
isPlayerInside = false;
|
||||
carController.ProcessInput(0f, 0f, true);
|
||||
|
||||
// Отвязываем цель и выключаем камеру авто
|
||||
if (carController != null) carController.ProcessInput(0f, 0f, true);
|
||||
|
||||
if (globalCarCamera != null)
|
||||
{
|
||||
globalCarCamera.SetTarget(null);
|
||||
globalCarCamera.gameObject.SetActive(false);
|
||||
}
|
||||
|
||||
|
||||
if (uiManager != null) uiManager.ToggleDashboard(false);
|
||||
|
||||
|
||||
CharacterController charController = playerInstance.GetComponent<CharacterController>();
|
||||
if (charController != null) charController.enabled = false;
|
||||
|
||||
playerInstance.transform.position = exitPoint.position;
|
||||
|
||||
|
||||
if (exitPoint != null)
|
||||
playerInstance.transform.position = exitPoint.position;
|
||||
else
|
||||
playerInstance.transform.position = transform.position - transform.right * 1.8f + Vector3.up * 0.5f;
|
||||
|
||||
if (charController != null) charController.enabled = true;
|
||||
|
||||
|
||||
playerInstance.SetActive(true);
|
||||
playerInstance = null;
|
||||
}
|
||||
@@ -74,14 +75,17 @@ public class VehicleInteraction : MonoBehaviour, IInteractable
|
||||
{
|
||||
if (!isPlayerInside) return;
|
||||
|
||||
float vertical = Input.GetAxis("Vertical");
|
||||
float horizontal = Input.GetAxis("Horizontal");
|
||||
bool isBraking = Input.GetKey(KeyCode.Space);
|
||||
if (carController != null)
|
||||
{
|
||||
float vertical = Input.GetAxis("Vertical");
|
||||
float horizontal = Input.GetAxis("Horizontal");
|
||||
bool isBraking = Input.GetKey(KeyCode.Space);
|
||||
|
||||
carController.ProcessInput(vertical, horizontal, isBraking);
|
||||
carController.ProcessInput(vertical, horizontal, isBraking);
|
||||
if (uiManager != null) uiManager.UpdateSpeed(carController.SpeedKmH);
|
||||
}
|
||||
|
||||
if (uiManager != null) uiManager.UpdateSpeed(carController.SpeedKmH);
|
||||
|
||||
if (Input.GetKeyDown(KeyCode.E)) ExitVehicle();
|
||||
if (Input.GetKeyDown(KeyCode.F) || Input.GetKeyDown(KeyCode.E))
|
||||
ExitVehicle();
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user