Files
VR-GAME/Assets/Script/PlayerController.cs

24 lines
721 B
C#

using UnityEngine;
public class PlayerController : MonoBehaviour
{
public Joystick joystick; // Kéo Fixed Joystick ở Canvas vào đây
public float moveSpeed = 2f;
void Update()
{
// Lấy input từ Joystick
float horizontal = joystick.Horizontal;
float vertical = joystick.Vertical;
// Di chuyển object theo trục X và Z
Vector3 direction = new Vector3(horizontal, 0, vertical).normalized;
transform.Translate(direction * moveSpeed * Time.deltaTime, Space.World);
// (Tùy chọn) Xoay object theo hướng di chuyển
if (direction != Vector3.zero)
{
transform.forward = direction;
}
}
}