当前位置:网站首页>【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 .
边栏推荐
- TS快速入门-函数
- Specification for fs4061a boost 8.4v charging IC chip and fs4061b boost 12.6V charging IC chip datasheet
- Advanced template
- Nine Qi single chip microcomputer ny8b062d single key control four LED States
- abc 258 G - Triangle(bitset)
- Upload avatar on uniapp
- 他做国外LEAD,用了一年时间,把所有房贷都还清了
- [monitoring] ZABBIX
- go踩坑——no required module provides package : go.mod file not found in current directory or any parent
- Cross domain request
猜你喜欢
如何避免电弧产生?—— AAFD故障电弧探测器为您解决
Netcore3.1 JSON web token Middleware
巩固表达式C# 案例简单变量运算
Paper notes multi UAV collaborative monolithic slam
Illustrated network: what is gateway load balancing protocol GLBP?
【雅思阅读】王希伟阅读P4(matching2段落信息配对题【困难】)
2022.07.03(LC_6108_解密消息)
两个数相互替换
Fast analysis -- easy to use intranet security software
NPM install error forced installation
随机推荐
Parsing of XML
Data on the number of functional divisions of national wetland parks in Qinghai Province, data on the distribution of wetlands and marshes across the country, and natural reserves in provinces, cities
NPM install error forced installation
GDB常用命令
如果炒股开华泰证券的户,在网上开户安全吗?
[paper reading] Tun det: a novel network for meridian ultra sound nodule detection
Build your own minecraft server with fast parsing
PermissionError: [Errno 13] Permission denied: ‘data. csv‘
JS how to realize array to tree
js如何实现数组转树
Face recognition 5- insight face padding code practice notes
The company needs to be monitored. How do ZABBIX and Prometheus choose? That's the right choice!
Enterprise application business scenarios, function addition and modification of C source code
How to save your code works quickly to better protect your labor achievements
Significance of acrel EMS integrated energy efficiency platform in campus construction
Learn C language from scratch day 024
Get to know ROS for the first time
Illustrated network: what is gateway load balancing protocol GLBP?
ORB(Oriented FAST and Rotated BRIEF)
Paper notes multi UAV collaborative monolithic slam