Methods and variables for the "Unity" 7.1 input class

Source: Internet
Author: User

Categories: Unity, C #, VS2015

Date Created: 2016-04-21 I. INTRODUCTION

In the input class, the key is corresponding to the physical key, such as the keyboard, mouse, joystick buttons, the mapping relationship cannot be changed, the programmer can use the key name or key code keycode to obtain its input status. For example, Cetkeydown (KEYCODE.A) returns True when you press the A key.

The following is the member variable of the input class:

The following is the member function of the input class:

Input axis (axis) and input manager

The input axis (axis) is used to simulate the smooth change of input, such as rocker changes, steering wheel rotation, etc., need to be configured in the input manager.

The input axis contains a plus or minus two virtual keys (Positive button and negative button). You can think of an input axis as a slider bar with a value of 1 on the left and a value of 1 on the right. When the positive key is pressed, the slider moves toward the right side, and when the negative key is pressed, the slider moves to the left negative direction. The position of the slider corresponds to the current value of the input axis.

A button is a virtual key defined in the input manager, accessed by name. Developers can create and name virtual keys as needed, and set up message mappings with physical keys (and their combinations). For example, unity defaults to creating a virtual key named "Fire1" for the user, and maps the message of the left and right "Ctrl" keys to Fire1.

Open the Edit-> proect->settings->input item in the menu bar to open the input manager.

The advantage of using virtual keys is that you have the flexibility to configure the input and allow the player to customize the keying input after the game is released. Therefore, the use of virtual keys is recommended in development.

You can add a new input axis to this interface, or you can change the settings for each axis here. Each axis can correspond to a joystick, two buttons of the mouse, or two keyboard keys.

The meanings of each parameter in the interface are explained below.

Names (name)

The string name used to check the axis in the script.

Description Name (descriptive name)

Configure dialog box to enter a positive name that is displayed in the tab for building independently.

Describe the negative name (descriptive negative name)

The configuration dialog box enters a negative name that is displayed in the tab for building independently.

Negative buttons (negative button)

Used to move the axis in the negative direction.

Positive buttons (Positive button)

Used to move the axis in the positive direction.

Alternate negative buttons (negative button)

The alternate button used to move the axis in the negative direction.

Alternate positive button (Alt Positive button)

The alternate button used to move the axis in the positive direction.

Gravity (Gravity)

When no button is pressed, the axis drops to 0 unit speed per second.

Death (Dead)

Simulates the size of the dead zone. All analog device values within this range will be mapped to 0.

Sensitivity (sensitivity)

The unit speed per second that the axial target value moves. This feature is only available for digital devices.

Snapping (SNAP)

If enabled, the axis value is automatically zeroed when the button in the opposite direction is pressed.

Reverse (Invert)

If enabled, pressing the negative button (negative button) will provide a positive value and vice versa.

Types (Type)

Controls the input type for this axis.

Axes (axis)

The axis of the connected device will control this axis.

Joystick (Joy Num)

Connecting the joystick will control this axis.

These settings can be used to fine-tune the look and feel of the input. They have tooltips in the editor. Third, use the input axis in the script

The following script can query the current state:

Value = Input.getaxis ("horizontal");

The axis values are between 1 and 1. The middle position is 0. This is in case of joystick input and keyboard input.

However, the mouse increment and window Shake increment refers to the distance that the mouse or window moves at the last frame. This means that when the user moves the mouse quickly, it may be greater than 1 or less than-1.

You can create multiple axes with the same name. The axis with the largest absolute value is returned when the input axis is obtained. This makes it possible to specify the same axis name for more than one input device. For example, create an axis for keyboard input, and another axis with the same name for the joystick. If the user uses a joystick, the input will come from the joystick, otherwise the input will come from the keyboard. With this approach, there is no need to consider the source of the input when scripting. Four, keyboard keys and mouse button name

To map a key to an axis, you must enter the key name in the positive button (Positive button) or negative button (negative button) property in the viewer.

Key names follow the following conventions:

? Standard key: "A", "B", "C" 、...

? number keys: "1", "2", "3", ...

? Arrow keys: On (UP), down (down), left (Ieft), right

? keypad key: "[1]", "[2]", "[3]", "[+]", "[=]"

? modifier keys: "Right Shift", "left Shift", "Ctrl", "Left Ctrl", "Alt", "left Alt", "correct cmd", "left Cmd"

mouse button: "Mouse 0", "Mouse 1", "Mouse 2", ...

The joystick button (from any joystick): "Joystick button 0", "joystick button 1", "Joystick button 2", ...

? joystick button (from specified joystick): "Joystick 1 button 0", "Joystick 1 button 1", "Joystick 2 button 0" 、...

? Special keys: "Backspace", "tab", "Return", "Escape", "Space", "delete", "enter", "Insert", "Home", "End", "Page Up", "Page Down"

? function keys: "F1", "F2", "F3" 、...

In the script interface and Viewer, the name used to identify the key is the same:

Value = Input.getkey ("a");

Methods and variables for the "Unity" 7.1 input class

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.