Plugin MQTT i test sceny testowej
This commit is contained in:
46
Assets/Scripts/MouseLook.cs
Normal file
46
Assets/Scripts/MouseLook.cs
Normal file
@@ -0,0 +1,46 @@
|
||||
using UnityEngine;
|
||||
using UnityEngine.InputSystem;
|
||||
|
||||
public class MouseLook : MonoBehaviour
|
||||
{
|
||||
public float mouseSensitivity = 100f;
|
||||
public Transform playerBody; // Tu przeci¹gniesz Fasolkê (Player)
|
||||
|
||||
private float xRotation = 0f;
|
||||
public bool canLook = false; // Zablokujemy obracanie przed startem
|
||||
|
||||
public void EnableLooking()
|
||||
{
|
||||
canLook = true;
|
||||
// Blokujemy kursor na œrodku ekranu i go chowamy
|
||||
Cursor.lockState = CursorLockMode.Locked;
|
||||
}
|
||||
|
||||
void Update()
|
||||
{
|
||||
if (!canLook) return;
|
||||
|
||||
if (Mouse.current == null)
|
||||
{
|
||||
Debug.LogError("Brak myszki!");
|
||||
return;
|
||||
}
|
||||
|
||||
Vector2 mouseDelta = Mouse.current.delta.ReadValue();
|
||||
|
||||
// Jeœli to zobaczysz w konsoli, znaczy ¿e system dzia³a, a problem jest w skali
|
||||
if (mouseDelta != Vector2.zero)
|
||||
{
|
||||
Debug.Log($"Ruch myszy: {mouseDelta}");
|
||||
}
|
||||
|
||||
float mouseX = mouseDelta.x * mouseSensitivity * 0.1f; // Zmniejszy³em mno¿nik dla testu
|
||||
float mouseY = mouseDelta.y * mouseSensitivity * 0.1f;
|
||||
|
||||
xRotation -= mouseY;
|
||||
xRotation = Mathf.Clamp(xRotation, -90f, 90f);
|
||||
|
||||
transform.localRotation = Quaternion.Euler(xRotation, 0f, 0f);
|
||||
playerBody.Rotate(Vector3.up * mouseX);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user