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?
- Using unityengine;
- Using system.collections;
- Public class Movecontroller:monobehaviour {
- Private Animator anim;
- Private Rigidbody rb;
- Private Float joypositionx;
- Private Float joypositiony;
- Private Float joyrox;
- Private Float joyroy;
- public Float speed = 5f;
- Private Playerhealth ph;
- Private EasyTouch ej;
- Private Float timer;
- void Awake ()
- {
- Anim = Gameobject.findgameobjectwithtag (tags.player). Getcomponent<animator> ();
- RB = anim.transform.rigidbody;
- ph = rb.transform.getcomponent<playerhealth> ();
- }
- First register the joystick movement and stop event
- void onenable ()
- {
- Easyjoystick.on_joystickmove + = onjoystickmove;
- Easyjoystick.on_joystickmoveend + = onjoystickmoveend;
- EJ = gameobject.getcomponent<easytouch> ();
- }
- //shift Lever End back
- void Onjoystickmoveend (movingjoystick move)
- {
- if (move.joystickname = = "move")
- {
- Anim. Setbool ("Move", false);
- Joypositionx = 0;
- Joypositiony = 0;
- }
- }
- void Update ()
- {
- if (ph.hp < 1 && ej.enable)
- {
- ej.enable = false;
- }
- }
[csharp]View PlainCopyprint?
- Rollback in joystick movement
- void Onjoystickmove (movingjoystick move)
- {
- Debug.Log ("error");
[csharp]View PlainCopyprint?
- 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
- if (move.joystickname = = "Rotate")
- {
- Joyrox = move.joystickaxis.x;
- Joyroy = move.joystickaxis.y;
- Rb.transform.LookAt (new Vector3 (rb.transform.position.x + joyrox, rb.transform.position.y, Rb.transform.position.z + joyroy));
- }
- else if (move.joystickname = = "move")
- {
- Anim. Setbool ("Move", true);
- Joypositionx = move.joystickaxis.x;
- Joypositiony = move.joystickaxis.y;
- /* Set the orientation of the role (toward current coordinates + joystick Offset)
- Transform. LookAt (new Vector3 (transform.position.x + joypositionx, transform.position.y, transform.position.z + joypositiony));
- Move the Player's position (move by Position)
- Transform. Translate (vector3.forward * Time.deltatime * 5);
- Play Run animation
- Rb. Moveposition (transform.position + new Vector3 (joypositionx, 0, joypositiony) * * time.deltatime); */
- }
- }
- }
okay, so you can control the rotation, that's it, It's easy!
Unity3d Double Stick EasyTouch