Plugin MQTT i test sceny testowej
This commit is contained in:
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);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user