Easy Touch Shake control character movement

Source: Internet
Author: User

Easy Touch Shake control character movement

public class Joystick:monobehaviour

{

public float speed; Define Speed

Private Charactercontroller CC; Define person Controller

Code startup

private void Ondisable ()

{

Start Call Onmove,onmoveend

Easyjoystick.on_joystickmove + = OnMove;

Easyjoystick.on_joystickmoveend + = Onmoveend;

}

private void OnDestroy ()

{

End Close Onmove,onmoveend

Easyjoystick.on_joystickmove-= OnMove;

Easyjoystick.on_joystickmoveend-= Onmoveend;

}

private void Start ()

{

CC = getcomponent<charactercontroller> ();//Get Controller

}

Touch Move Method

public void OnMove (Movingjoystick move)

{

Determine if it is easy Touch shake sense

if (move.joystickname! = "New joystick")

{

Return

}

Define and move left and right

float Joypositionx = move.joystickaxis.x;

float joypositiony = move.joystickaxis.y;

Judging before and after moving

if (joypositiony! = 0 | | Joypositionx! = 0)

{

Defining coordinates

Vector3 moveposition = new Vector3 (Joypositionx, 0, Joypositiony);

Defining coordinate increments

Vector3 dir = transform.position + moveposition;

Orientation oriented

Transform. LookAt (dir);

Positioning move

Vector3 MoVector3 = transform.forward*time.deltatime*speed;

First person move

Cc. Move (MOVECTOR3);

}

}

End of touch Move method

public void Onmoveend (Movingjoystick move)

{

Debug.Log ("Touch Lift")

}

}

Note: Using this method must be done after importing the easy touch plug-in, typically for non-PC-side use.

Easy Touch Shake control character movement

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.