Unity Script--13 Input Control--03 mobile device 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.

Mobile devices, such as mobile phones, tablets and other devices that touch the screen by finger, Unity has a dedicated interface to detect the position status of individual fingers that interact with the screen.

The information for the finger that touches the screen corresponds to an object named Touch, which can be used by the input.touches variable to get all the touch

Touch-Commonly used parameters

Fingerid: Phone number, integral type

Phase: The stage of the mobile phone, enumeration type, divided into these stages: began start touch screen, moved move, stationary static, ended finger off screen, canceled system off touch

Position: The position of the finger touching the screen, the Vector2 type, coordinates in the lower left corner of the screen for the origin 1 pixels corresponding to a unit

For example: the resolution of the IPhone 4s is 960x640, so if the application is a horizontal screen, then the lower left corner of the position is (0,0), the upper right corner of the position is (960,640)

1 measurement

Get the phone information and output to the screen, here first basic introduction

usingUnityengine;usingSystem.Collections; Public classC_3_8_3_1:monobehaviour {voidOngui () {//Traverse all Touch        foreach(Touch Touchinchinput.touches) {//Output Touch InformationGuilayout.label (string. Format ("finger: {0} Status: {1} location: {2}", Touch.fingerid,touch.phase.tostring (), touch.position)); }    }}

2 Gravity Sensor

Acceleration, i.e. acceleration sensing or gravity sensing

There are many games where the main operation is based on Gravity sensing, for example: Mega jump and Froggy Jump

To output gravity-sensing information to the screen by code, observing that the device is rotated in a different direction is a change in the Input.acceleration value

usingUnityengine;usingSystem.Collections; Public classC_3_8_3_2:monobehaviour {voidOngui () {Guilayout.label ("X:"+input.acceleration.x); Guilayout.label ("Y:"+INPUT.ACCELERATION.Y); Guilayout.label ("Z:"+input.acceleration.z); }}

3 other

Input also has an interface to get information about the device input when the device is running the game, and the following is a brief introduction to several interfaces

With Input.deviceorientation you can get the current game running direction

The input.touchsupported can be used to get the current game to support finger touch operation

You can set whether the game supports multi-touch with input.multitouchenabled.

Unity Script--13 Input Control--03 mobile device 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.