First Commit

This commit is contained in:
bybohka committed 2026-11-19 23:24:44 +03:00
commit eed6b79efc
2836 files changed
+948481

No files matched your search

@@ -0,0 +1,53 @@
using UnityEngine;
public class PlayerLook : MonoBehaviour
{
[Header("Look Settings")]
[SerializeField] private float mouseSensitivity = 150f;
[SerializeField] private Transform playerBody;
private float xRotation = 0f;
public float Sensitivity => mouseSensitivity;
private void Awake()
{
if (playerBody == null) playerBody = transform.parent != null ? transform.parent : transform;
mouseSensitivity = PlayerPrefs.GetFloat("perekup_sensitivity", mouseSensitivity);
}
private void Start()
{
// Блокируем курсор в центре экрана и скрываем его (если не открыто меню)
GameInputLock.ApplyCursor();
}
public void SetSensitivity(float value)
{
mouseSensitivity = Mathf.Clamp(value, 20f, 600f);
PlayerPrefs.SetFloat("perekup_sensitivity", mouseSensitivity);
}
/// <summary>Поворот взгляда в заданном направлении (после телепорта/выхода из машины).</summary>
public void ResetPitch(float pitch = 0f)
{
xRotation = pitch;
transform.localRotation = Quaternion.Euler(xRotation, 0f, 0f);
}
public void ProcessLook(Vector2 input)
{
float mouseX = input.x * mouseSensitivity * Time.deltaTime;
float mouseY = input.y * mouseSensitivity * Time.deltaTime;
// Расчет наклона камеры с ограничением, чтобы нельзя было сломать шею
xRotation -= mouseY;
xRotation = Mathf.Clamp(xRotation, -90f, 90f);
// Применяем вращение камеры (вверх/вниз)
transform.localRotation = Quaternion.Euler(xRotation, 0f, 0f);
// Вращаем само тело игрока (влево/вправо)
playerBody.Rotate(Vector3.up * mouseX);
}
}