Unity Script--13 Input control--02 Custom input

Source: Internet
Author: User

Study Notes for beginners, please correct me if you have any mistakes. The number is also please point out, thank you.

Keyboard and mouse input detection is very limited, generally only for computers and other devices, the following describes another method

Custom input can be set input type name, input device type, input key parameters, so as to easily solve the computer and home machine input compatibility

Click on the Navigation menu bar "Edit" Project Settings input to open the Import settings interface

Unity provides the default input settings, including:

Horizontal transverse movement

Vertical longitudinal movement

Firel fire button, etc. input

Name: Names

Descriptive name: Positive names displayed in control settings

Descriptive negative name: negative names displayed in control settings

Negative button: It is used to move the axis in a negative direction

Positive button: It is used to move the axis in the positive direction

Alt Negative button: Alternate buttons for moving axes in negative direction

Alt Positive button: Alternate buttons for moving axes in true direction

Gravity: When not yo u related button pressed, regression 0 speed, units/sec

Dead: Analog dead-zone size, set range all analog devices have a value of 0

Sensitivity: Sensitivity, unit/sec, for digital devices only

Snap: If enabled, the axis value is reset to 0 when the button in the opposite direction is pressed

Invert: If used, the negative button will provide a positive value and vice versa

Type: Input device types for control axes

Axis: The axis of the connecting device will control this axis

Joy Num: Connecting the joystick will control this axis

Can find a lot of keys, such as horizontal are duplicated, this is because all keys keyboard Mouse is a single set of key, and the handle is another set, for example: Firel Fire key 1 divided into keyboard mouse version and mobile version

1 button

Keyboard Mouse : Keyboard Mouse Implementation button is very simple

1 Setting Type: First set type to key or Mouse Button

2 fill in the name: here name is filled with Firel

3 Set the key: because it is a single button, so just need to fill in the positive part, Positive button to fill the left Ctrl,alt Positive button fill 0, that is, the keyboard control key on either side or the mouse left button are corresponding to open rockets

handle : Step and keyboard mouse exactly the same, just the keyboard name is not the same, here positive button filled in is joystick button 0

script : When the keys are set in the input manager interface, we can monitor the input via scripting, such as code:

usingUnityengine;usingSystem.Collections; Public classC_3_8_2_1:monobehaviour {voidUpdate () {//Press the Fire1 key        if(Input.getbuttondown ("Fire1"))        {            //...        }        //Press and hold the Fire1 key        if(Input.getbutton ("Fire1"))        {            //...        }        //release the Fire1 key        if(Input.getbuttonup ("Fire1"))        {            //...        }    }}

2 direction axis

Directional axes are commonly used to control the movement of players ' characters left and right or up and down

His settings page and buttons are exactly the same, but the usage is not the same, the direction axis has two buttons corresponding to the plus or minus two directions,

Take the horizontal direction axis For example, such as, press the right arrow of the keyboard is positive, shout down the left key of the keyboard is a negative value, the output range is " -1,1" floating point number, we can use it to control the movement of the character

Keyboard Mouse : The first few steps and buttons, just need additional settings gravity, Dead, sensitivity, snap and other parameters

Gravity fill 3 means that when the corresponding button is released, the output value will be quickly zeroed at 3/s

Dead fill in 0.001 indicates that the output is ignored when it is between [ -0.001,0.001], forcing the output to 0

Sensitivity fill in 3 means that when the button corresponds to the button, the output value will change at 3/second, when the forward button is pressed to quickly reach 1, when the negative button is pressed, it will arrive quickly-1

handle : This is no longer the handle button but the handle shaft.

1 Setting Type: First set type to joystick Axis

2 Fill in Name: Here Name heaven and earth is horizontal

3 Set handle: Joy num column if the get Motion from all joysticks represents all handles, you can also fill in the joystick 1 handle sequence number

4 Setting the axis: Axis column here is x axis, which is the horizontal of the handle cross key

Script: The code for the script to get the axes is very simple

using Unityengine; using System.Collections;  Public class c_3_8_2_2:monobehaviour {    void  Update () {        // Gets the value of the horizontal axis         float axish = Input.getaxis ("horizontal");}    }

Unity Script--13 input Control--02 custom input

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.