当前位置:网站首页>【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 .
边栏推荐
- [Peking University] tensorflow2.0-1-opening
- 模板的进阶
- Specification for fs4061a boost 8.4v charging IC chip and fs4061b boost 12.6V charging IC chip datasheet
- Distributed base theory
- 2022.07.03 (LC 6109 number of people who know secrets)
- JS convert pseudo array to array
- How many triangles are there in the golden K-line diagram?
- 微服务(Microservice)那点事儿
- How to avoid arc generation—— Aafd fault arc detector solves the problem for you
- Hisilicon 3559 universal platform construction: YUV422 pit stepping record
猜你喜欢
ORB(Oriented FAST and Rotated BRIEF)
Oracle case: SMON rollback exception causes instance crash
他做国外LEAD,用了一年时间,把所有房贷都还清了
Hash table, hash function, bloom filter, consistency hash
Build your own minecraft server with fast parsing
Every time I look at the interface documents of my colleagues, I get confused and have a lot of problems...
Detailed explanation of openharmony resource management
图解网络:什么是网关负载均衡协议GLBP?
Parsing of XML
abc 258 G - Triangle(bitset)
随机推荐
图解网络:什么是网关负载均衡协议GLBP?
URLs and URIs
【C】(笔试题)指针与数组,指针
Fast parsing intranet penetration helps enterprises quickly achieve collaborative office
圖解網絡:什麼是網關負載均衡協議GLBP?
P4408 [NOI2003] 逃学的小孩(树的直径)
兩個數相互替換
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
雅思考试流程、需要具体注意些什么、怎么复习?
Is it safe to open and register new bonds? Is there any risk? Is it reliable?
skimage: imread & imsave & imshow
[Peking University] tensorflow2.0-1-opening
同事的接口文档我每次看着就头大,毛病多多。。。
JS convert pseudo array to array
Go pit - no required module provides Package: go. Mod file not found in current directory or any parent
go踩坑——no required module provides package : go.mod file not found in current directory or any parent
P4281 [AHOI2008]紧急集合 / 聚会(LCA)
Summer challenge brings you to play harmoniyos multi terminal piano performance
(script) one click deployment of any version of redis - the way to build a dream
js如何实现数组转树