It's easy to use a joystick joystick that has been introduced in unity since. But it also has a lot of limitations, not all to meet the needs of ordinary MMO hand-tours, such as: to be able to easily better material, can be specified in an area display, or only when the area is touched, and so on. With these features, the easy touch plugin has been implemented for you. All are configurable. You can buy from the asset store or use the free version.
(can be freely shared, please specify the original source http://blog.csdn.net/janeky/article/details/17364903)
Use the last example to achieve it. Control the movement of a role
1.import "Easy Touch 3" Resource pack
2. Create a character model
3. Create a terrain
4. Add an instance of Joystick: Hedgehog team->easy touch->extensions->add a new Joystick. Then we can see it coming out in the lower left corner.
5. Set the relevant parameters of the joystick, see
6. Create a new script MoveController.cs to receive the joystick events and control the movement of the characters. The code is as follows:
[CSharp]View PlainCopy
- Using Unityengine;
- Using System.Collections;
- Public class Movecontroller:monobehaviour {
- void onenable ()
- {
- Easyjoystick.on_joystickmove + = Onjoystickmove;
- Easyjoystick.on_joystickmoveend + = Onjoystickmoveend;
- }
- //shift lever End
- void Onjoystickmoveend (Movingjoystick move)
- {
- //Stop, role recovery idle
- if (move.joystickname = = "Movejoystick")
- {
- Animation. Crossfade ("idle");
- }
- }
- //Move the lever
- void Onjoystickmove (Movingjoystick move)
- {
- if (move.joystickname! = "Movejoystick")
- {
- return;
- }
- //Get the coordinates of the center offset of the joystick
- float Joypositionx = move.joystickaxis.x;
- float joypositiony = move.joystickaxis.y;
- if (joypositiony! = 0 | | Joypositionx! = 0)
- {
- //Set the orientation of the character (toward the current coordinate + 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
- Animation. Crossfade ("Run");
- }
- }
- }
Finish the work, the specific
Finally, let's take a look at the parameters of Easy touch
Easy Touch offers a virtual joystick solution that can be adapted to your every need. Including the previous mentioned, custom UI, hide, specify the area and so on. You can try it out in your project
Unity Hand Tour < six > Game joystick easy Touch 3 tutorial