User input-Unity3d game development Training

Source: Internet
Author: User

User input-Unity3d game development Training

Deng Jiahai

Time: 2018-02-12-14:28:45

User Inputs input

Mouse buttons:

-Method: Getmousebutton ();

-Method: Getmousebuttondown ()

-Method: Getmousebuttonup ()

-The parameter is int,0 for left key, 1 for right, 2 for wheel

Keyboard input

-Method: GetKey ()

-Method: Getkeydown ()

-Method: Getkeyup ()

-The parameter is a KeyCode enumeration, which indicates a key pressed

Control Object

Controlling the position, rotation, and scaling of objects

Location: Property position, Method translate ()

Rotation: Method Rotate (), Method Rotatearound ()

Scaling: Property Localscale

Class Vector3: Represents a three-dimensional vector that can be understood as a point in a three-dimensional space

-member up, down, left, fight, forward, back, zero, one

Entity3d API

Click Help->unity Manual

Figure 3-1

The API documentation is opened in the browser.

Figure 3-2

Figure 3-3

Create a new two scene. File->new sence

Figure 3-4

Create a new empty object create->create empty, name script,reset a bit tranform

Create a new C # script, double-click Open Script

Figure 3-5

The script originally looked like this, nothing, only two methods:

1 usingUnityengine;2 3 usingSystem.Collections;4 5 ///Author: Deng Jiahai6 7 ///Users: Dengjiahai8 9 ///Date Created: 2017-01-10 22:50:52Ten  One ///Modify: A  - ///version: V 1.0.0.0 -  the //Add a menu name -  -[Addcomponentmenu ("Demo2/inputtest1")] -  +  Public classInputtest:monobehaviour { -  +   A  at     //Use this for initialization -  -     voidStart () { -  -     -  in     } -  to     +  -     //Update is called once per frame the  *     voidUpdate () { $ Panax Notoginseng         if(Input.getbutton ("Fire1")) -  the         { +  APrint"Button"); the  +         } -  $         if(Input.getbuttondown ("Fire1")) $  -         { -  thePrint" Down"); - Wuyi         } the  -         if(Input.getbuttonup ("Fire1")) Wu  -         { About  $Print" up"); -  -         } -  A     } +  the}

Select the new script scene, and then Edit->project Settings->input, and then set the properties of input.

Figure 3-6

Figure 3-7

Window->console Open the console, the console is typically used for printing error messages or debugging.

Debug it.

Figure 3-8

Vector3

Figure 3-9

Figure 3-10

Figure 3-11

1 usingUnityengine;2 usingSystem.Collections;3 4 5 6  Public classExampleclass:monobehaviour {7     voidSlide (Transform target, Vector3 raildirection) {8Vector3 heading = target.position-transform.position;9Vector3 force =vector3.project (heading, raildirection);TenGetcomponent<rigidbody>(). Addforce (force); One     } A}

Figure 3-12

1 usingUnityengine;2 usingSystem.Collections;3 4 5 6  Public classExampleclass:monobehaviour {7      PublicTransform Startmarker;8      PublicTransform Endmarker;9      Public floatSpeed =1.0F;Ten     Private floatStartTime; One     Private floatjourneylength; A     voidStart () { -StartTime =Time.time; -Journeylength =vector3.distance (startmarker.position, endmarker.position); the     } -     voidUpdate () { -         floatdistcovered = (time.time-starttime) *Speed ; -         floatFracjourney = distcovered/journeylength; +Transform.position =Vector3.lerp (startmarker.position, endmarker.position, Fracjourney); -     } +}

User input-Unity3d game development Training

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.