using System.Collections; using System.Collections.Generic; using UnityEngine; using UnityEngine.InputSystem; using UnityEngine.InputSystem.XR; public class PlayerController : MonoBehaviour { public PlayerInputController playerInputController; //输入事件 public Rigidbody2D rb; public Vector2 inputDirection;//输入方向的数值 public float moveSpeed;//速度 private void Awake() { playerInputController = new PlayerInputController(); rb = GetComponent(); } void Start() { } private void OnEnable() { playerInputController.Enable(); } private void OnDisable() { playerInputController.Disable(); } void Update() { inputDirection = playerInputController.GamePlayer.Move.ReadValue();//读取数值 //wasd移动 } private void FixedUpdate() { Move(); } public void Move() { rb.velocity = new Vector2(inputDirection.x * moveSpeed, inputDirection.y * moveSpeed); //wasd移动 } }