- Learning C# 7 By Developing Games with Unity 2017(Third Edition)
- Micael DaGra?a Greg Lukosek
- 244字
- 2021-07-02 19:59:40
Making decisions based on user input
Decisions always have to be made when the user provides input. The input can arrive from different types of interfaces depending on the platform that we are working on. For example, if we are developing games for mobile phones, we would use the touch screen as an input for swipe, touch, touch with two fingers, and so on, while for game consoles we would use the gamepad buttons. For each button, we can assign an action and it's possible to combine multiple buttons (inputs) to perform different actions. Another important aspect that we need to consider is that when we press a key or a button, three different inputs are happening at that instance, GetKey, GetKeyDown, and GetKeyUp:

As we can see in the preceding description, we can assign three different actions for the same key, so we are not limited to only one option. Previously in this chapter, we used an example where the user had to press the Enter key to call the AddTwoNumbers() method:
if(Input.GetKeyUp(Keycode.Return)) AddTwoNumbers();
The if statement's condition becomes true only when the Return key is released after being pressed down.
Notice that the code of AddTwoNumbers() isn't between two curly brackets. When there is only one line of code to execute for an if or else statement, you have the option of not using the curly brackets.
Here's a partial screenshot of the GetKeyUp() method, as shown in Unity's Scripting Reference:

- Kibana Essentials
- C++程序設計(第3版)
- C語言程序設計習題解析與上機指導(第4版)
- PostgreSQL技術內幕:事務處理深度探索
- 編譯系統透視:圖解編譯原理
- Python數據可視化之Matplotlib與Pyecharts實戰
- 硅谷Python工程師面試指南:數據結構、算法與系統設計
- PHP編程基礎與實例教程
- Quantum Computing and Blockchain in Business
- 持續集成與持續交付實戰:用Jenkins、Travis CI和CircleCI構建和發布大規模高質量軟件
- ExtJS Web應用程序開發指南第2版
- R語言數據挖掘:實用項目解析
- 軟件設計模式(Java版)
- C語言程序設計實驗指導
- 深入實踐C++模板編程