Unity's input inputs

Source: Internet
Author: User

The input manager in unity is manipulated by the inputs class. Official Document Address: https://docs.unity3d.com/ScriptReference/Input.html

Chinese translation can be here: http://www.ceeger.com/Script/Input/Input.html

Here are just a few confusing points to talk about.

Since there are already getkey, Getkeydown, Getkeyup and Getmousebutton, Getmousebuttondown, Getmousebuttonup, why should there be Getbutton, What about Getbuttondown and getbuttonup?

Down, up, respectively, the press, release, Key, Mouse is easy to understand: The keyboard, mouse, GetKey, Getmouse said that after the press did not release the action, similar to the presses.

We know that the key position of the keyboard is fixed, the left and right mouse button is fixed, that is, the mapping relationship is fixed. The button is the virtual device defined by the input manager InputManager, which is accessed by name. How to understand, look first.

The setup of input can open the panel by edit–> Project settings–> input

If I need to decide whether to jump, I can write this in the code.

if (Input.getbuttondown ("jump")) {    Debug.Log ("Input button Jump. " );}

Run, when the SPACEBAR is pressed, the console outputs "Input button down jump." And if the positive Button modified, not space is also K, at this time when you press the K on the keyboard, the console will have output, and press the space bar is not responding. It is mapped by name, which is more flexible than the previous key and mouse.

The left, middle, and right keys of a mouse event correspond to values 0, 2, 1, respectively.

if (Input.getmousebutton (0)) {    // left button is pressed and placed in the Update method will be continuously triggered }if (Input.getmousebuttondown (1)) {    // Right-click }if (Input.getmousebuttonup (2)) {    // Middle key lifted     }

Keyboard-corresponding characters can be directly obtained by keycode, the following code when the keyboard a key is pressed to add a "button" corresponding to the current node, when the D key is pressed to delete a node.

if(Input.getkeydown (keycode.a)) {Button Newbutton=instantiate (button); NewButton.transform.SetParent ( This. Gameobject.transform,false);}Else if(Input.getkeydown (KEYCODE.D)) {button[] buttonchilds= gameobject.getcomponentsinchildren<button>(); List<Button> buttonlist =NewList<button>(Buttonchilds); intNcount =Buttonlist.count; if(Ncount >1) {Button Tmpbutton= Buttonlist[ncount-1];    Destroy (Tmpbutton.gameobject); }}

The Getaxis can be used to make a rocker (upper, lower, left, right, and A, W, S, D) to move (Translate), rotate (Rotate) the game object. The range of return values is [-1, 1], you can set the interval size, such as only increase, minus 0.01 each time, details can see the official website video: Https://unity3d.com/cn/learn/tutorials/topics/scripting/getaxis

Unity's input inputs

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.