25. Unity3d mobile phone Input class touch detailed-unity touch screen event resolution (Twisted Fate)

Source: Internet
Author: User

First, paste the model file types supported by unity, which have not been previously collected.

Unity supports two types of 3D file formats:

1. generic "Export-type"3D file

File formats such as . FBX,. Dae,. 3DS,. DXF,. obj , and so on.

2.3D Software-specific 3D file format

Formats such as Max, Maya, blender,cinema4d, Modo, Lightwave & cheetah3d , etc. supported by the software . MAX,. MB,. MA and so on.

Unity3d phone in the input class touch detailed:

1.input.touchcount touch grows with 50 increments in one second.

2.input.gettouch (0). phase==touchphase.moved the state of the last frame slide in the finger slide is moving.

Several states of 3.TouchPhase touch.

4.touch.deltaposition Increment position (Input.gettouch (0). deltaposition) The value of the last frame slide, returning only the XY axis coordinates, also available Vector3 (z-axis 0), so generally with vector2 receive.

1 Static varAa:int;2 function Update () {3 if(input.touchcount>0)4 {5 print (input.touchcount);6 }7 }8 function Ongui ()9 {TenGui. Label (Rect ( the, the, the, the),"SDFF"); One}

Touchcount refers to the number of touch frames. Note that the touch event can only be run on the emulator or on the real machine (tested pass), about a second touch. Touchcount+50 times or so. 2.input.touches Touch list.

//Prints number of fingers touching the screen//output Touch the number of fingers on the screenfunction Update () {varFingercount =0; for(varTouch:touchinchinput.touches) {if(Touch.phase! = touchphase.ended && Touch.phase! =touchphase.canceled) Fingercount++;}if(Fingercount >0) Print ("User has"+ Fingercount +"Finger (s) touching the screen");}

3. Let cube move the code with touch:

Static varCountint;//define the number of TouchcountvarParticle_:gameobject;//defines the cube object to be storedvarTouchposition:vector3;//Store moving three-dimensional coordinate valuesfunction Update () {if(input.touchcount>0) {Count+=Input.touchcount;}if((input.touchcount>0&&input.gettouch (0). phase==touchphase.moved))//[color=red] If the finger touch is clicked and the state of the finger touch is moving [/color]{touchposition=input.gettouch (0). Deltaposition;//[color=red] gets the XY axis distance of the last frame movement of the finger Touch [/color]Particle_.transform. Translate (touchposition.x*0.01, touchposition.y*0.01,0);//[color=red] Move this distance [/color]}}function Ongui () {GUI. Label (Rect (Ten,Ten, -, -),"Cishu:"+count. ToString ()); Gui. Label (Rect (Ten, -, -, -), Touchposition. ToString ());}

Moving objects:

usingUnityengine;usingSystem.Collections; Public classExample:monobehaviour { Public floatSpeed =0.1F; voidUpdate () {if(Input.touchcount >0&& Input.gettouch (0). Phase = =touchphase.moved) {Vector2 touchdeltaposition= Input.gettouch (0). deltaposition; Transform. Translate (-touchdeltaposition.x * speed,-TOUCHDELTAPOSITION.Y * speed,0); }    }}

Click Collision Clone:

usingUnityengine;usingSystem.Collections; Public classExample:monobehaviour { PublicGameobject Projectile; voidUpdate () {inti =0;  while(I <input.touchcount) {if(Input.gettouch (i). Phase = =Touchphase.began) Clone= Instantiate (Projectile, transform.position, transform.rotation) asGameobject; ++i; }    }}

Click on the screen, Ray method to emit a particle

usingUnityengine;usingSystem.Collections; Public classExample:monobehaviour { PublicGameobject particle; voidUpdate () {inti =0;  while(I <input.touchcount) {if(Input.gettouch (i). Phase = =Touchphase.began) {ray Ray=Camera.main.ScreenPointToRay (Input.gettouch (i). position); if(Physics.raycast (Ray)) instantiate (particle, transform.position, transform.rotation) asGameobject; }            ++i; }    }}

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.