当前位置:网站首页>Unity technical manual - getKey and getaxis and getbutton
Unity technical manual - getKey and getaxis and getbutton
2022-06-25 22:57:00 【Hua Weiyun】
This article is about 3.3 Thousand characters , Novice reading needs 11 minute , Review needs 3 minute 【 Collect at any time, no longer get lost 】
About author
as everyone knows , Life is a long process , constantly overcome difficulties , Constantly reflect on the process of progress . In this process, there will be a lot of questions and thoughts about life , So I decided to put my thinking , Share all your experiences and stories , To find resonance !!!
Focus on Android/Unity And various game development skills , as well as Share various resources ( Website 、 Tools 、 material 、 Source code 、 Games etc. )
If you need anything, welcome me , Communication groups make learning No longer alone .

Premise
This is what Xiao Kong insisted on writing Unity Novice series , Welcome to taste .
Novice (√√√)
bosses (√)
Practice process
GetKey
GetKey When pressing and lifting the key of the corresponding parameter on the keyboard, return to true, Will trigger instantly N many times , Long press will trigger all the time , Not used at ordinary times , However, it may be used for functions like pressing and firing .
GetKeyDown When Press down Parameter corresponds to the name of the keyboard That frame return true, It is triggered only once at the moment of pressing , Commonly used .
GetKeyUp When lift Parameter corresponds to the name of the keyboard That frame return true, The lifting moment is triggered only once , Commonly used .
The above three method parameters are KeyCode Or key characters ( A lowercase letter ), Contains a lot of , At the bottom of the article is the key description .
void Update(){ if (Input.GetKey(KeyCode.W)) { print(" Press the keyboard w"); } if (Input.GetKey("f5")) { print(" Press the keyboard f5"); } if (Input.GetKeyDown(KeyCode.S)) { print(" Press the keyboard s"); } if (Input.GetKeyDown("d")) { print(" Press the keyboard d"); } if (Input.GetKeyUp(KeyCode.Q)) { print(" Press the keyboard q"); } if (Input.GetKeyUp("tab")) { print(" Press the keyboard tab"); }}GetAxis
Return from axisName The value of the identified virtual axis . The return is float type , stay -1 To 1 Between .
give an example : The default value is 0, Hold down 【D】 or 【→】 From 0 Growth to 1, Finally keep 1, Release from 1 Return to 0. Others in the same way .
This value is independent of the frame rate , Disorderly worry about frame rate changes .
It mainly controls the upper, lower, left and right , It is often used to control character movement , The default is 【WASD】 Key and the left side of the keypad 【 The up and down or so 】 Arrow keys .
print(“ keyboard : Vertical value -1 To 1:”+Input.GetAxis(“Vertical”));
print(“ keyboard : Horizontal value -1 To 1:”+Input.GetAxis(“Horizontal”));
print(“ touch : The mouse moves along the screen X Trigger when moving -1 To 1:”+Input.GetAxis(“Mouse X”));
print(“ touch : The mouse moves along the screen Y Trigger when moving -1 To 1:”+Input.GetAxis(“Mouse Y”));
print(“ touch : Triggered when the mouse scroll wheel scrolls -1 To 1:”+Input.GetAxis(“Mouse ScrollWheel”));
Default can be passed in Edit-Input Manager- Several input controls in .

After the weight removal, there are still 11 Parameters can be passed :

Can be found in Edit-Project Setting-Input Set or modify , General default , After all, everyone has developed a certain habit of keyboard keys .
If the top GetAxis Smoothing is not enough for you , Want to handle smoothness yourself , It can be used. Input.GetAxisRaw function , This function does not press... By default 0 Or return to 0, The key range is -1 and 1.
GetButton
GetButtonDown It means that the mouse button will be pressed once
GetButton It means that the pressing process is executed many times and the mouse is pressed and held for a long time , It can be used for weapon firing function
GetButtonUp It means that it will only be executed once after the mouse is pressed and released
It's all about string Type string , Default can be passed in Edit-Input Manager- Several input controls in . and GetAxis Same parameter .

other
author : Xiaokong and Xiaozhi Xiaokong
Reprint note - Be sure to indicate the source :https://zhima.blog.csdn.net/
This Taoist friend, please Step back ️, I watch you Extraordinary bearing , There is a king's domineering spirit in his speech , There will be a great achievement in the future !!! There is give the thumbs-up Collection Today I tell you , Have you ordered it , Your success in the future ️, I don't take a penny , If it doesn't work ️, Or come back to me .
边栏推荐
- Research Report on China's new energy technology and equipment market competition analysis and marketing strategy suggestions 2022-2028
- Use of local stack in flask
- Canoe: the fifth simulation project: simulation + test
- Three layer architecture + routing experiment
- Unity技术手册 - 粒子基础主模块属性-上
- [invitation letter] on March 4, the platform enabled digital intelligence Innovation -- UFIDA BiP PAAS cloud platform IUAP digital intelligence hundred cities forum · Jinan Station
- Basic concepts of processor scheduling
- China bed and mattress market status research analysis and development prospect forecast report (2022)
- Does jQuery cache any selectors- Does jQuery do any kind of caching of “selectors”?
- Travel notes of 2022giao
猜你喜欢

字符串变形(字符串大小写切换和变现)

Use apiccloud AVM multi terminal component to quickly realize the search function in the app

万亿热钱砸向太空经济,真的是一门好生意?

简单好用的缓存库 gcache

1281_FreeRTOS_vTaskDelayUntil实现分析

腾讯《和平精英》新版本将至:新增账号安全保护系统,游戏内违规行为检测升级

Another breakthrough! Alibaba cloud enters the Gartner cloud AI developer service Challenger quadrant

Zhihu Gaozan: what ability is important, but most people don't have it?

2022-2028 global selective laser sintering service industry research and trend analysis report

Data governance is easier said than done
随机推荐
Analysis of China's tractor manufacturing and operation situation and forecast report of prospect trend 2022-2028
Research and Analysis on the current situation of Chinese acne drug market and forecast report on its development prospect (2022)
在线CRUDhasone关联查询报错Unabletouseinternalvariable:List
Basic concepts of processor scheduling
华为云短信测了很多手机都提示发送频繁
你好,请问老师,在支付宝基金开户真的安全吗?
简单好用的缓存库 gcache
Intimacy - [comfortable exit] - final communication to reduce injury
EVC, VVC, lcevc test: how about the performance of the latest MPEG codec?
Zhihu Gaozan: what ability is important, but most people don't have it?
Nacos source code analysis 01 code structure
作为一个程序员我们如何快乐的学习成长进步呢?(个人感悟和技术无关)
【WPF】CAD工程图纸转WPF可直接使用的xaml代码技巧
Ribbon core ⼼ source code analysis
如何用jmeter做接口测试
记|一次exists关键字的学习记录
Global and Chinese flame retardant ABS industry development trend and market demand analysis report 2022 ~ 2028
Talk about adapter mode
MySQL数据库索引
[intensive lecture] 2022 PHP intermediate and advanced interview questions (II)