当前位置:网站首页>【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 .
边栏推荐
- [IELTS reading] Wang Xiwei reading P3 (heading)
- Huawei employs data management experts with an annual salary of 2million! The 100 billion market behind it deserves attention
- 分布式BASE理论
- abc 258 G - Triangle(bitset)
- Tester's algorithm interview question - find mode
- Face recognition 5- insight face padding code practice notes
- JS convert pseudo array to array
- [monitoring] ZABBIX
- JS 将伪数组转换成数组
- 2022.07.03(LC_6109_知道秘密的人数)
猜你喜欢

What is the difference between port mapping and port forwarding

The waterfall flow layout demo2 (method 2) used by the uniapp wechat applet (copy and paste can be used without other processing)

URLs and URIs

abc 258 G - Triangle(bitset)

人脸识别5- insight-face-paddle-代码实战笔记

Fast parsing intranet penetration helps enterprises quickly achieve collaborative office
Date time type and format in MySQL

js如何实现数组转树

【selenium自动化】常用注解

leetcode494,474
随机推荐
Ap8022 switching power supply small household appliances ACDC chip offline switching power supply IC
Robot reinforcement learning synergies between pushing and grassing with self supervised DRL (2018)
Daily practice (18): stack containing min function
How to save your code works quickly to better protect your labor achievements
Go step on the pit - no required module provides package: go mod file not found in current directory or any parent
"Xiaodeng" domain password policy enhancer in operation and maintenance
The pit of sizeof operator in C language
Remember to build wheels repeatedly at one time (the setting instructions of obsidian plug-in are translated into Chinese)
Every time I look at the interface documents of my colleagues, I get confused and have a lot of problems...
If you open an account of Huatai Securities by stock speculation, is it safe to open an account online?
分布式BASE理论
基本放大电路的学习
他做国外LEAD,用了一年时间,把所有房贷都还清了
Using fast parsing intranet penetration to realize zero cost self built website
1189. Maximum number of "balloons"
Specification for fs4061a boost 8.4v charging IC chip and fs4061b boost 12.6V charging IC chip datasheet
How to use fast parsing to make IOT cloud platform
【雅思阅读】王希伟阅读P4(matching2段落信息配对题【困难】)
Power operation and maintenance cloud platform: open the new mode of "unattended and few people on duty" of power system
P4408 [NOI2003] 逃学的小孩(树的直径)
