当前位置:网站首页>【Unity】InputSystem
【Unity】InputSystem
2022-07-05 00:28:00 【A salted fish that likes playing games】
InputSystem
Install the required plug-ins
version 1.3.0
Unity At first, I didn't meet the current multi platform and various input devices , The design of the initial input system was difficult to meet many requirements, so InputSystsem.
Installation requirements :
Unity2019.4 and .Net 4 Above version .
install :
Go directly to the package manager Window > Package Manager Can be installed , Prompt for restart after installation , It can be used after restart .
Be careful :
1、InputSystem With part Unity The built-in functions are not yet compatible , Use as appropriate , Details refer to Official documents .
2、 If you want to switch the input system , You can go to Edit > Project Settings > Player stay Other Settings You can choose either of the two input methods in , It can also be used at the same time .
Use
1、 establish Input Actions Components
There are two ways to create :
1、 Right click Create-->Input Actions establish

2、 Mount the component on the object you want to control Player Input Back click Create Actions establish .

2、 Mount the component on the object you want to control Player Input, Components as shown in the above figure , Then bind the corresponding Input Actions.
If you want to create a jump , Shooting and other actions , You can double-click to create Input Actions Or select this file and click Edit asset
Enter the configuration interface 
Click the plus sign to create Action Map,Action And bind keys 

As shown in the figure above ,Behavior There are many patterns , the Send Messages, Using this mode will call the methods in the information shown below .
jumping
Will SendMessage() to GameOject: OnDeviceLost, OnDeviceRegained,OncontrolsChanged, OnJump
So we want to trigger the event when the button is clicked , You need to create a method with the corresponding method name , Created a Player Script file and mount it on the object , Create the following script file :
using UnityEngine.InputSystem;// The namespace to be referenced
using UnityEngine;
public class PlayerController : MonoBehaviour
{
public void OnJump()
{
transform.Translate(Vector3.up);
Debug.Log(" jumping ");
}
}
Successfully executed after running :
Move
change Input Actions, Add one Action,
Action Type by Value,Control Type by Vector 2
Delete the binding below 
Right click to Action
Create a combination of up, down, left and right 
Bind the corresponding key
Create the following script :
using UnityEngine.InputSystem;
using UnityEngine;
public class PlayerController : MonoBehaviour
{
void OnMove(InputValue value)
{
Debug.Log(value.Get<Vector2>());
}
}
Through the test, we can find that the output is :
So the mobile code can be :
using UnityEngine.InputSystem;
using UnityEngine;
public class PlayerController : MonoBehaviour
{
public float MoveSpeed;
void OnMove(InputValue value)
{
transform.Translate(value.Get<Vector2>()*MoveSpeed*Time.deltaTime);
}
}
But in this case, continuous movement cannot be achieved , Because the event can only respond once when the key is pressed .
边栏推荐
- [paper reading] cavemix: a simple data augmentation method for brain vision segmentation
- Get to know ROS for the first time
- Daily practice (18): stack containing min function
- Some basic functions of enterprise projects are developed, and important things are saved to online first a
- IT转测试岗,从迷茫到坚定我究竟付出了什么?
- How to do the project of computer remote company in foreign Internet?
- 【路径规划】RRT增加动力模型进行轨迹规划
- Tester's algorithm interview question - find mode
- IELTS examination process, what to pay attention to and how to review?
- TS quick start - functions
猜你喜欢
随机推荐
Actual combat simulation │ JWT login authentication
Summary of week 22-07-02
Acrel-EMS综合能效平台在校园建设的意义
P4281 [ahoi2008] emergency assembly / gathering (LCA)
Deux nombres se remplacent
If you open an account of Huatai Securities by stock speculation, is it safe to open an account online?
[paper reading] Tun det: a novel network for meridian ultra sound nodule detection
Hologres Query管理及超时处理
IELTS examination process, what to pay attention to and how to review?
The pit of sizeof operator in C language
[IELTS reading] Wang Xiwei reading P4 (matching1)
P3304 [SDOI2013]直径(树的直径)
Some basic functions of enterprise projects are developed, and important things are saved to online first a
[IELTS reading] Wang Xiwei reads P4 (matching2 paragraph information matching question [difficult])
Multilingual Wikipedia website source code development part II
Leetcode70 (Advanced), 322
P3304 [sdoi2013] diameter (diameter of tree)
巩固表达式C# 案例简单变量运算
Kibana index, mapping, document operation
Using fast parsing intranet penetration to realize zero cost self built website






![[IELTS reading] Wang Xiwei reading P4 (matching1)](/img/91/1b3f85410035f65acb0c205185f698.png)



