using System.Collections; using System.Collections.Generic; using UnityEngine; [RequireComponent(typeof(Rigidbody2D), typeof(BoxCollider2D))] public class PlayerJoystick2D : MonoBehaviour { [SerializeField] private Joystick joystick; public float moveSpeed = 5.0f; Rigidbody2D rb; Vector2 movement; void Start() { rb = GetComponent(); } void FixedUpdate() { movement.x = joystick.Horizontal; movement.y = joystick.Vertical; rb.MovePosition(rb.position + movement * moveSpeed * 0.02f); } }