首页 > 解决方案 > Unity 使用 PS4 控制器旋转对象

问题描述

我是 Unity 新手,但我正在尝试使用控制器输入(右摇杆)围绕 Y 轴旋转对象。因此,如果将杆向右推,则对象将向右旋转。到目前为止,这是我的代码。

public class TurnBall : MonoBehaviour {

    PlayerControls controls;
    Vector2 aim;

    void Awake() {
        controls = new PlayerControls();
        controls.Gameplay.Aim.performed += ctx => aim = ctx.ReadValue<Vector2>();
        controls.Gameplay.Aim.canceled += ctx => aim = Vector2.zero;
    }

    void Update() {
        transform.Rotate(0, aim.x, 0, Space.World);
    }

    void onEnable() {
        controls.Gameplay.Enable();
    }

    void onDisable() {
        controls.Gameplay.Disable();
    }
}

提前致谢!!

标签: unity3d

解决方案


推荐阅读