RogueLike/Assets/Scipts/PlayerController.cs
2025-04-07 21:57:07 +08:00

60 lines
1.1 KiB
C#

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<Rigidbody2D>();
}
void Start()
{
}
private void OnEnable()
{
playerInputController.Enable();
}
private void OnDisable()
{
playerInputController.Disable();
}
void Update()
{
inputDirection = playerInputController.GamePlayer.Move.ReadValue<Vector2>();//读取数值 //wasd移动
}
private void FixedUpdate()
{
Move();
}
public void Move()
{
rb.velocity = new Vector2(inputDirection.x * moveSpeed, inputDirection.y * moveSpeed); //wasd移动
}
}