tạo bóng rổ assest tạo bóng ném
This commit is contained in:
24
Assets/Script/PlayerController.cs
Normal file
24
Assets/Script/PlayerController.cs
Normal file
@@ -0,0 +1,24 @@
|
||||
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;
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user