参考:https://connect.unity.com/p/unity-xin-inputsystem-de-jian-yao-shi-yong

参考:https://connect.unity.com/p/unityxin-yi-dai-shu-ru-xi-tong-jie-shao

 

这块资料是真的少,晚上可以查的是讲的广那种,但是单个怎么使用反而不详细

我的游戏至少有2种输入方式,键盘和手柄

 

1.首先,在packmanager里面安装input system

Unity新版输入系统 new input system

 

 画红线的地方是unity官方的一个demo案例

 

2.注意player setting这边的设置

Unity新版输入系统 new input system

 

 自行调整使用那种输入系统

 

3.项目工程里,右键Create->Input Actions  编辑

Unity新版输入系统 new input system

 

 左上角那个东西是一个控制单,比如因为有键盘手柄,所以建立2份控制单

新建控制单时候,一定要添加你的控制单输入类型,我就是忘记了这个死活弄不出,比如键盘的话就是这个,Ps4控制器就添加Ps4 Controller

Unity新版输入系统 new input system

 

 4.调用

一种是通过自动生成代码

一种是使用 Player Input

Unity新版输入系统 new input system

 

 使用Player Input的话,注意Behavior的类型

 

    public void OnShoot(InputAction.CallbackContext callback)
    {
        //回调阶段
        switch (callback.phase)
        {
            //启动阶段,最先
            case InputActionPhase.Started:
                Debug.Log("Started + Attacking!"); 
                break;
            //执行阶段
            case InputActionPhase.Performed:
                Debug.Log("Performed + Attacking!");
                break;
            //按键抬起阶段
            case InputActionPhase.Canceled:
                Debug.Log("Canceled + Attacking!");
                break;
        }
    }

 

相关文章:

  • 2021-08-01
  • 2022-12-23
  • 2021-12-26
  • 2021-06-21
  • 2021-11-27
  • 2022-12-23
  • 2021-12-03
猜你喜欢
  • 2021-07-28
  • 2021-12-31
  • 2021-04-12
  • 2021-11-22
  • 2021-07-01
  • 2022-12-23
  • 2021-08-16
相关资源
相似解决方案