Unity3d Double Stick EasyTouch

Source: Internet
Author: User

First create an instance of a stick

I'm here to change the name to move

Copy the name Rotate.

Tick the dynamic display so that the user clicks on the joystick (now the joystick game is displayed dynamically)

Set the position of the joystick (one in the lower left and one in the lower Right)

Click on the bottom left of the screen

The character moves directly with the joystick to control the Player's (x, z) don't forget to set the speed so that the player can move with the joystick

***********************************************************************

Spin we use code to control

Preferred Setting joystick type

Create a new empty object TOUCH binding control script (i'm just going to stick it right here, everybody ignores the other variables)

[csharp]View PlainCopyprint?
  1. Using unityengine;
  2. Using system.collections;
  3. Public class Movecontroller:monobehaviour {
  4. Private Animator anim;
  5. Private Rigidbody rb;
  6. Private Float joypositionx;
  7. Private Float joypositiony;
  8. Private Float joyrox;
  9. Private Float joyroy;
  10. public Float speed = 5f;
  11. Private Playerhealth ph;
  12. Private EasyTouch ej;
  13. Private Float timer;
  14. void Awake ()
  15. {
  16. Anim = Gameobject.findgameobjectwithtag (tags.player). Getcomponent<animator> ();
  17. RB = anim.transform.rigidbody;
  18. ph = rb.transform.getcomponent<playerhealth> ();
  19. }
  20. First register the joystick movement and stop event
  21. void onenable ()
  22. {
  23. Easyjoystick.on_joystickmove + = onjoystickmove;
  24. Easyjoystick.on_joystickmoveend + = onjoystickmoveend;
  25. EJ = gameobject.getcomponent<easytouch> ();
  26. }
  27. //shift Lever End back
  28. void Onjoystickmoveend (movingjoystick move)
  29. {
  30. if (move.joystickname = = "move")
  31. {
  32. Anim.  Setbool ("Move", false);
  33. Joypositionx = 0;
  34. Joypositiony = 0;
  35. }
  36. }
  37. void Update ()
  38. {
  39. if (ph.hp < 1 && ej.enable)
  40. {
  41. ej.enable = false;
  42. }
  43. }
[csharp]View PlainCopyprint?
    1. Rollback in joystick movement
    2. void Onjoystickmove (movingjoystick move)
    3. {
    4. Debug.Log ("error");
  
[csharp]View PlainCopyprint?
  1. The following is the determination of the name of the stick to do the corresponding processing player coordinates plus the shift of the joystick to reset the player's direction
  2. if (move.joystickname = = "Rotate")
  3. {
  4. Joyrox = move.joystickaxis.x;
  5. Joyroy = move.joystickaxis.y;
  6. Rb.transform.LookAt (new Vector3 (rb.transform.position.x + joyrox, rb.transform.position.y,  Rb.transform.position.z + joyroy));
  7. }
  8. else if (move.joystickname = = "move")
  9. {
  10. Anim.  Setbool ("Move", true);
  11. Joypositionx = move.joystickaxis.x;
  12. Joypositiony = move.joystickaxis.y;
  13. /* Set the orientation of the role (toward current coordinates + joystick Offset)
  14. Transform. LookAt (new Vector3 (transform.position.x + joypositionx, transform.position.y, transform.position.z + joypositiony));
  15. Move the Player's position (move by Position)
  16. Transform. Translate (vector3.forward * Time.deltatime * 5);
  17. Play Run animation
  18. Rb. Moveposition (transform.position + new Vector3 (joypositionx, 0, joypositiony) * * time.deltatime); */
  19. }
  20. }
  21. }

okay, so you can control the rotation, that's it, It's easy!

Unity3d Double Stick EasyTouch

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.