点击之前创建的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...
PlayerControls inputActions;//声明 InputSystem的脚本对象 Vector2 movementInput;//存储 WASD输入的值 public void OnEnable() { //获取设备上的输入 if (inputActions == null) { inputActions = new PlayerControls(); //绑定输入的值 inputActions.PlayerMovement.MovementAction.performed += outputActions =...
// 输入控制类的实例privateTestInputControls InputControls;voidOnEnable(){ InputControls =newTestInputControls();// 创建输入控制实例InputControls.Player.Fire.started += OnFireDown;// 注册开火开始动作的回调InputControls.Player.Fire.performed += OnLongPress;// 注册长按动作的回调InputControls.Player.Fir...
2. Edit->Project Settings->Player->Other Settings->Active Input Handling,改成new或者both。 3. Unity的Project中右键->Create->Input Actions。 4. Action Maps取名,如Player。Actions右边小“+”添加New action,取名如:Action_Move,表示鼠标移动。此时对应Properties->Action->Action Type: Pass Through; Cont...
这里点击Yes,则启用Input System,放弃旧的。我们选择Yes。 以上操作所影响选项是Project Settings-Player中Active Input Handing属性,这里根据个人需求去选择。 同时开启-选择Both,相对方便临时的测试。 Support Device 2022/6/8更新 InputSystem默认支持所有的输入设备,为了用户自定义InputSystem支持我们自定义配置支持的设...
}input_MoveDir=newVector2(input_X,input_Y);}privatevoidOnMoveCanceled(UnityEngine.InputSystem.InputAction.CallbackContextobj){input_X=0;input_Y=0;input_MoveDir=Vector2.zero;}privatevoidFixedUpdate(){Move();}privatevoidMove(){playerRB.MovePosition(playerRB.position+input_MoveDir*moveSpeed*Time....
如果是键盘WASD,我们需要添加一个2D Vector Composite。 得到下面的输入,绑定上WASD即可。 接下来就是设置Player Input组件的回调了,我们在代码中需要给InputAction.CallbackContext变量的输入,这个会将摇杆的输入作为参数传入到函数中,然后通过ReadValue来读取指定的类型。 Player Input中设置如下。 最后的问题,就是关于...
InputSystem起作用的设置 我们选用“Input System Package(New)”或者“Both”都可以。 Input System的使用方式大致分为两种,一种是通过InputSysten Package提供的组件,在编辑器通过拖拽,选择,挂载等方式,进行函数与输入动作的绑定;另一种是使用代码对函数与输入动作进行绑定。
1.首先,在packmanager里面安装input system 画红线的地方是unity官方的一个demo案例 2.注意player setting这边的设置 自行调整使用那种输入系统 3.项目工程里,右键Create->Input Actions 编辑 左上角那个东西是一个控制单,比如因为有键盘手柄,所以建立2份控制单 ...
步骤一:在Package Manager安装Input System 步骤二:右键Create/InputActions,新建一个输入控制器(例如命名为ActionContr...