Input for Unity Android devices

Source: Internet
Author: User

Input for Unity Android devices

1 based on screen position input

Sometimes it is for the whole of some style of clean, reduce the screen UI icon, so that the virtual button to abandon the usual input method. In order to replace the input mode of the virtual key, the movement of the object is controlled according to the location of the click event in the screen. For example, the entire phone screen is divided into two areas, the left area is responsible for mobile control, the right area responsible for the release of skills.

Here are the issues we need to deal with are click event Acquisition and screen information acquisition, the following two aspects of the API documentation.

Click event: Http://wiki.ceeger.com/script/unityengine/classes/touch/touch

Screen information: Http://wiki.ceeger.com/script/unityengine/classes/screen/screen

1 voidUpdate () {2 3         if(Input.touchcount >0)//determine if there is touch information4         {5              for(inti =0; i < Input.touchcount; i++)6             {7Touch touch = input.touches[i];//passing touch information to touch8 9                 if(touch.phase = = Touchphase.stationary | | touch.phase = = touchphase.moved)//Touch.phase is the phase information of the touch, determined by the Touchphase enumeration to determine the current state, began: one finger begins to touch; Moved: one finger moves; stationary: one finger touches the screen but no movement occurs; Ended : A finger leaves the screen and is the final state; cnaceled: The system cancels the touch monitoring, such as when the user puts the screen on his face or more than five contacts simultaneously. Ten                 { OneTouchposition = touch.position;//Gets the location information for the touch, which is consistent with the screen coordinates.  A                     if(Touchposition.x < screenwidth/4)//ScreenWidth has been assigned =>screenwidth = Screen.width in start; -                     { -SomeMethod1 ();//a Method 1 theBeetransform.translate (NewVector3 (-movespeed,-downspeed,0), Space.world);//Beetransform is the location information of the game object and has been assigned in start -                     } -                     Else if(touchposition.x>=screenwidth/4&& touchposition.x <screenwidth/2) -                     { + SomeMethod1 (); -Beetransform.translate (NewVector3 (Movespeed,-downspeed,0), Space.world); +  A                     } at                 } -                 Else if(Touch.phase = =touchphase.ended) -SOMEMETHOD2 ();//a method -             } -         } -  in         if(Input.touchcount = =0)//when not touched - SomeMethod2 (); to}

Input for Unity Android devices

Related Article

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.