点击之前创建的InputSystemAsset,在Inspector面板勾选Generate C# Class。Project面板里会多出一个InputSystemAsset.cs文件。创建C#文件PlayerController.cs,将其挂载到Sphere上,按下WASD小球可以移动。using System; using System.Collections; using System.Collections.Generic; using UnityEngine; using static InputSystem...
Input System Package(New):只采用新版的Input System方式,旧版的Input将不再起作用。 Both:两种方式同时起作用 InputSystem起作用的设置 我们选用“Input System Package(New)”或者“Both”都可以。 Input System的使用方式大致分为两种,一种是通过InputSysten Package提供的组件,在编辑器通过拖拽,选择,挂载等方式,...
3. Unity的Project中右键->Create->Input Actions。 4. Action Maps取名,如Player。Actions右边小“+”添加New action,取名如:Action_Move,表示鼠标移动。此时对应Properties->Action->Action Type: Pass Through; Control Type: Vector 2. 继续添加Binding:Mouse->Positions. 5. 设置鼠标触发事件。New action:Actio...
一种是使用 Player Input 使用Player Input的话,注意Behavior的类型 publicvoidOnShoot(InputAction.CallbackContext callback) {//回调阶段switch(callback.phase) {//启动阶段,最先caseInputActionPhase.Started: Debug.Log("Started + Attacking!");break;//执行阶段caseInputActionPhase.Performed: Debug.Log("Per...
这里点击Yes,则启用Input System,放弃旧的。我们选择Yes。 以上操作所影响选项是Project Settings-Player中Active Input Handing属性,这里根据个人需求去选择。 同时开启-选择Both,相对方便临时的测试。 Support Device 2022/6/8更新 InputSystem默认支持所有的输入设备,为了用户自定义InputSystem支持我们自定义配置支持的设...
如果是键盘WASD,我们需要添加一个2D Vector Composite。 得到下面的输入,绑定上WASD即可。 接下来就是设置Player Input组件的回调了,我们在代码中需要给InputAction.CallbackContext变量的输入,这个会将摇杆的输入作为参数传入到函数中,然后通过ReadValue来读取指定的类型。 Player Input中设置如下。 最后的问题,就是关于...
();input_X=moveDir.x;input_Y=moveDir.y;if(input_X!=0&&input_Y!=0){input_X=input_X*0.7f;input_Y=input_Y*0.7f;}input_MoveDir=newVector2(input_X,input_Y);}privatevoidOnMoveCanceled(UnityEngine.InputSystem.InputAction.CallbackContextobj){input_X=0;input_Y=0;input_MoveDir=Vector2...
通过Package Manager安装好InputSystem之后可以同时导入一些范例资源,阅读其使用代码,InputSystem有几种不同的使用方法,开发时应按需求酌情选择。 需要注意的是,安装好InputSystem之后会有提示询问是否切换到新版输入管理系统,切换后Input Setting面板将失效,游戏中也无法使用Input类获取输入。
通过Package Manager安装好InputSystem之后可以同时导入一些范例资源,阅读其使用代码,InputSystem有几种不同的使用方法,开发时应按需求酌情选择。 需要注意的是,安装好InputSystem之后会有提示询问是否切换到新版输入管理系统,切换后Input Setting面板将失效,游戏中也无法使用Input类获取输入。