当前位置:网站首页>【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 .
边栏推荐
- P4281 [ahoi2008] emergency assembly / gathering (LCA)
- 如果炒股开华泰证券的户,在网上开户安全吗?
- go踩坑——no required module provides package : go.mod file not found in current directory or any parent
- 城市轨道交通站应急照明疏散指示系统设计
- 实战模拟│JWT 登录认证
- Hash table, hash function, bloom filter, consistency hash
- 如何避免电弧产生?—— AAFD故障电弧探测器为您解决
- 电力运维云平台:开启电力系统“无人值班、少人值守”新模式
- He worked as a foreign lead and paid off all the housing loans in a year
- 打新债开户注册安全吗?有没有风险的?靠谱吗?
猜你喜欢
Application of multi loop instrument in base station "switching to direct"
js如何实现数组转树
企业公司项目开发好一部分基础功能,重要的事保存到线上第一a
How to avoid arc generation—— Aafd fault arc detector solves the problem for you
同事的接口文档我每次看着就头大,毛病多多。。。
Every time I look at the interface documents of my colleagues, I get confused and have a lot of problems...
两个数相互替换
leetcode518,377
基于三维gis平台的消防系统运用
Réseau graphique: Qu'est - ce que le Protocole d'équilibrage de charge de passerelle glbp?
随机推荐
(script) one click deployment of any version of redis - the way to build a dream
How many triangles are there in the golden K-line diagram?
跨域请求
Verilog tutorial (11) initial block in Verilog
abc 258 G - Triangle(bitset)
电力运维云平台:开启电力系统“无人值班、少人值守”新模式
Summary of week 22-07-02
Build your own minecraft server with fast parsing
Application of fire fighting system based on 3D GIS platform
Complete knapsack problem (template)
P4281 [AHOI2008]紧急集合 / 聚会(LCA)
22-07-02周总结
JS convert pseudo array to array
【北京大学】Tensorflow2.0-1-开篇
Remember to build wheels repeatedly at one time (the setting instructions of obsidian plug-in are translated into Chinese)
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
Daily practice (18): stack containing min function
Upload avatar on uniapp
[IELTS reading] Wang Xiwei reading P3 (heading)
IT转测试岗,从迷茫到坚定我究竟付出了什么?