当前位置:网站首页>【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 .
边栏推荐
- What did I pay for it transfer to testing post from confusion to firmness?
- Face recognition 5- insight face padding code practice notes
- A new method for analyzing the trend chart of London Silver
- 海思3559万能平台搭建:YUV422的踩坑记录
- Significance of acrel EMS integrated energy efficiency platform in campus construction
- NPM install error forced installation
- URL和URI
- Date time type and format in MySQL
- 他做国外LEAD,用了一年时间,把所有房贷都还清了
- Every time I look at the interface documents of my colleagues, I get confused and have a lot of problems...
猜你喜欢

NPM install error forced installation
![[IELTS reading] Wang Xiwei reading P3 (heading)](/img/19/40564f2afc18fe3e34f218b7b44681.png)
[IELTS reading] Wang Xiwei reading P3 (heading)

Some basic functions of enterprise projects are developed, and important things are saved to online first a

Hash table, hash function, bloom filter, consistency hash

《论文笔记》Multi-UAV Collaborative Monocular SLAM

Face recognition 5- insight face padding code practice notes

Continuous modification of business scenario functions

Learning of basic amplification circuit

【selenium自动化】常用注解

OpenHarmony资源管理详解
随机推荐
[paper reading] cavemix: a simple data augmentation method for brain vision segmentation
Continuous modification of business scenario functions
[IELTS reading] Wang Xiwei reading P4 (matching1)
Verilog tutorial (11) initial block in Verilog
PermissionError: [Errno 13] Permission denied: ‘data. csv‘
巩固表达式C# 案例简单变量运算
如何有效对直流列头柜进行监测
2022.07.03 (lc_6111_counts the number of ways to place houses)
(脚本)一键部署redis任意版本 —— 筑梦之路
GDB common commands
Robot reinforcement learning synergies between pushing and grassing with self supervised DRL (2018)
OpenHarmony资源管理详解
Get to know ROS for the first time
Date time type and format in MySQL
Cross domain request
Application of fire fighting system based on 3D GIS platform
ORB(Oriented FAST and Rotated BRIEF)
TS quick start - functions
Go pit - no required module provides Package: go. Mod file not found in current directory or any parent
【北京大学】Tensorflow2.0-1-开篇
