Plugin MQTT i test sceny testowej
This commit is contained in:
43
Assets/Scripts/GameManager.cs
Normal file
43
Assets/Scripts/GameManager.cs
Normal file
@@ -0,0 +1,43 @@
|
||||
using UnityEngine;
|
||||
using UnityEngine.InputSystem;
|
||||
using UnityEngine.InputSystem.Utilities;
|
||||
|
||||
public class GameManager : MonoBehaviour
|
||||
{
|
||||
[Header("UI do ukrycia")]
|
||||
public GameObject startCanvas;
|
||||
|
||||
[Header("Komponenty gracza")]
|
||||
public PlayerMove movementScript;
|
||||
public MouseLook lookScript;
|
||||
|
||||
// public MqttCollector mqttScript; // Odkomentujesz to póŸniej
|
||||
|
||||
private bool hasStarted = false;
|
||||
|
||||
void Start()
|
||||
{
|
||||
// Blokada na starcie
|
||||
if (movementScript != null) movementScript.enabled = false;
|
||||
if (lookScript != null) lookScript.canLook = false;
|
||||
|
||||
Cursor.lockState = CursorLockMode.None;
|
||||
Cursor.visible = true;
|
||||
|
||||
// Czekamy na dowolny klawisz
|
||||
InputSystem.onAnyButtonPress.CallOnce(ctrl => Begin());
|
||||
}
|
||||
|
||||
void Begin()
|
||||
{
|
||||
if (hasStarted) return;
|
||||
hasStarted = true;
|
||||
|
||||
if (startCanvas != null) startCanvas.SetActive(false);
|
||||
if (movementScript != null) movementScript.enabled = true;
|
||||
if (lookScript != null) lookScript.EnableLooking();
|
||||
|
||||
// if (mqttScript != null) mqttScript.BeginSession();
|
||||
Debug.Log("Gra wystartowa³a!");
|
||||
}
|
||||
}
|
||||
2
Assets/Scripts/GameManager.cs.meta
Normal file
2
Assets/Scripts/GameManager.cs.meta
Normal file
@@ -0,0 +1,2 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 9814a729a72ea7245aee98f3c0831d15
|
||||
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);
|
||||
}
|
||||
}
|
||||
2
Assets/Scripts/MouseLook.cs.meta
Normal file
2
Assets/Scripts/MouseLook.cs.meta
Normal file
@@ -0,0 +1,2 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 193d4aae75625f743847d5e870a3190a
|
||||
27
Assets/Scripts/PlayerMove.cs
Normal file
27
Assets/Scripts/PlayerMove.cs
Normal file
@@ -0,0 +1,27 @@
|
||||
using UnityEngine;
|
||||
using UnityEngine.InputSystem; // Dodaliœmy to!
|
||||
|
||||
public class PlayerMove : MonoBehaviour
|
||||
{
|
||||
public float speed = 5f;
|
||||
private CharacterController controller;
|
||||
|
||||
void Start() => controller = GetComponent<CharacterController>();
|
||||
|
||||
void Update()
|
||||
{
|
||||
// Nowy sposób pobierania WASD
|
||||
Vector2 moveInput = Vector2.zero;
|
||||
|
||||
if (Keyboard.current != null)
|
||||
{
|
||||
if (Keyboard.current.wKey.isPressed) moveInput.y = 1;
|
||||
if (Keyboard.current.sKey.isPressed) moveInput.y = -1;
|
||||
if (Keyboard.current.aKey.isPressed) moveInput.x = -1;
|
||||
if (Keyboard.current.dKey.isPressed) moveInput.x = 1;
|
||||
}
|
||||
|
||||
Vector3 move = transform.right * moveInput.x + transform.forward * moveInput.y;
|
||||
controller.Move(move * speed * Time.deltaTime);
|
||||
}
|
||||
}
|
||||
2
Assets/Scripts/PlayerMove.cs.meta
Normal file
2
Assets/Scripts/PlayerMove.cs.meta
Normal file
@@ -0,0 +1,2 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 734bc5370b4ebc247a55af3b053ed716
|
||||
Reference in New Issue
Block a user