First Commit
This commit is contained in:
commit
eed6b79efc
2836 files changed
+948481
No files matched your search
@@ -0,0 +1,60 @@
|
||||
using UnityEngine;
|
||||
|
||||
public class CarOrbitCamera : MonoBehaviour
|
||||
{
|
||||
[Header("Цель")]
|
||||
private Transform target; // Убрали SerializeField, теперь цель задается через код
|
||||
[SerializeField] private Vector3 targetOffset = new Vector3(0, 1.2f, 0);
|
||||
|
||||
[Header("Настройки орбиты")]
|
||||
[SerializeField] private float distance = 5.5f;
|
||||
[SerializeField] private float mouseSensitivity = 150f;
|
||||
|
||||
[Header("Ограничения")]
|
||||
[SerializeField] private float yMinLimit = 0f;
|
||||
[SerializeField] private float yMaxLimit = 80f;
|
||||
|
||||
private float currentX = 0f;
|
||||
private float currentY = 20f;
|
||||
|
||||
// НОВЫЙ МЕТОД: Принимает новую машину и сразу сбрасывает углы
|
||||
public void SetTarget(Transform newTarget)
|
||||
{
|
||||
target = newTarget;
|
||||
ResetCameraAngles();
|
||||
}
|
||||
|
||||
private void Start()
|
||||
{
|
||||
if (target != null)
|
||||
{
|
||||
currentX = target.eulerAngles.y;
|
||||
}
|
||||
}
|
||||
|
||||
private void LateUpdate()
|
||||
{
|
||||
if (target == null) return; // Если цели нет (игрок пешком), камера ничего не делает
|
||||
|
||||
currentX += Input.GetAxis("Mouse X") * mouseSensitivity * Time.deltaTime;
|
||||
currentY -= Input.GetAxis("Mouse Y") * mouseSensitivity * Time.deltaTime;
|
||||
|
||||
currentY = Mathf.Clamp(currentY, yMinLimit, yMaxLimit);
|
||||
|
||||
Quaternion rotation = Quaternion.Euler(currentY, currentX, 0);
|
||||
Vector3 focusPoint = target.position + targetOffset;
|
||||
Vector3 position = focusPoint - (rotation * Vector3.forward * distance);
|
||||
|
||||
transform.position = position;
|
||||
transform.rotation = rotation;
|
||||
}
|
||||
|
||||
public void ResetCameraAngles()
|
||||
{
|
||||
if (target != null)
|
||||
{
|
||||
currentX = target.eulerAngles.y;
|
||||
currentY = 20f;
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user