The movement of the Unity character with whose fingers (the first way)

Source: Internet
Author: User

Long night, no sleep, knock on the code, the more knock more and more! I found a lot of children are playing the bear haunt xxxx This game, incredibly played all afternoon did not play through the 2nd pass, I put the test also called to accompany me to play together!

As a result, he also can not get through, I go to call planning, he did not play, I went to call the director, he still did not play, I go back to call the test using game modification Master, modify the gem to buy the complete department of equipment! He still hasn't called!

(this game, let my life has become meaningless!) )

The character moves with the movement of the finger:

The first way: How many fingers move, the protagonist will move how much! ( I use this way, there is a problem, the finger too fast slide, the protagonist will slowly with the finger distance!) )

The second way: where the finger moves, the protagonist moves slowly to the position where the finger is located! ( Have not written the code, in theory will not appear the first problem), it is recommended this way to achieve

Part of the code implementation in the first way:
usingUnityengine;usingSystem.Collections;/// <summary>///the movement of the characters/// </summary> Public classplayermove:monobehaviour{Private BOOLIsmove; PrivateVector3 recordmousedownposition;//record the seat of the mouse click      Public floatSpeed =1;  PublicUisprite Gamebackground;  PublicUi2dsprite player;  Publicui2dspriteanimation playeranimation;  PublicSprite playerleftstate;  PublicSprite playerrightstate; Private floatAreawidth; Private floatAreaheight; //boundary of character Movement    voidAwake () {//Gets the width and height of the background spriteAreawidth= Gamebackground.drawingdimensions.z-player.drawingdimensions.z; Areaheight= GAMEBACKGROUND.DRAWINGDIMENSIONS.W-PLAYER.DRAWINGDIMENSIONS.W; }    //Start Moving     Public voidPlayerstartmove () {Ismove=true; Recordmousedownposition=input.mouseposition; }    //End Move     Public voidPlayerendmove () {Ismove=false; }    voidlateupdate () {if(ismove) {//Mouse Current coordinates-click the recorded coordinatesVector3 dir = input.mouseposition-recordmousedownposition; //Toggle left and right character picture status              if(Dir.x >0) {Debug.Log ("Switch to left"); Playeranimation.enabled=false; Player.nextsprite=playerrightstate; }            Else if(Dir.x <0) {Debug.Log ("right-turn picture"); Playeranimation.enabled=false; Player.nextsprite=playerleftstate; }            Else if(Dir.x = =0) {playeranimation.enabled=true; }            //let the character move in the direction of the finger                This. transform.localposition =NewVector3 (transform.localposition.x+ dir.x *0.7f, TRANSFORM.LOCALPOSITION.Y+ Dir.y *0.7f, TRANSFORM.LOCALPOSITION.Z); //prevent running out of the right border              if(Transform.localposition.x > Areawidth && dir.x >0)            {                 This. transform.localposition =NewVector3 (Areawidth, TRANSFORM.LOCALPOSITION.Y, t            RANSFORM.LOCALPOSITION.Z); }            //prevent running out of the left border              if(Transform.localposition.x <-areawidth && Dir.x <0)            {                 This. transform.localposition =NewVector3 (-areawidth, TRANSFORM.LOCALPOSITION.Y, transform.localposition.z); }            //prevent the upper border from running              if(Transform.localposition.y > Areaheight && dir.y >0)            {                 This. transform.localposition =NewVector3 (transform.localposition.x, Areaheight,            TRANSFORM.LOCALPOSITION.Z); }            //prevent running out of the lower border              if(Transform.localposition.y <-areaheight && Dir.y <0)            {                 This. transform.localposition =NewVector3 (transform.localposition.x,-areaheight, transform.localposition.z); } recordmousedownposition=input.mouseposition; }    }}

The movement of the Unity character with whose fingers (the first way)

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.