“This is the 26th day of my participation in the Gwen Challenge in November. Check out the details: The Last Gwen Challenge in 2021.”

Used to introduce

The best way to control the character’s movement is to use joystick events. The most used joystick plugin EastyJoystick is part of the EasyTouch joystick.

Import and download a good resource package, that is, EasyTouch plug-in

Add a joystick/button:

Set the joystick parameters in the Inspector:

  • Proerties: Set the rocker properties

  • Position & Size: Position and Size of the rocker

  • Joystick Axes Properties & Events: Axes attributes & Events

  • Joystick: Texture image

  • Dynamic joystick: Indicates whether it is a Dynamic joystick. That is, the joystick appears when the finger is pressed down.

  • Anchor: Preset position Default Lower Left(Left and right corner)

  • Offset: indicates the Offset. Others: adjust the size of the rocker, etc.

  • Interaction Type:

  • Direct Drag the object directly onto the enable axis and select Interaction effects.

  • Event Notification: indicates the Event Notification mode.

Implement the Buton button using the panel property action

Use code to implement the Button Button

Button above code:

using UnityEngine;

public class quest1 : MonoBehaviour
{

    void Start()
    {
        EasyButton.On_ButtonDown += Show;  // Register events
    }
    
    void Show(string name)    // Custom methods, note: must correspond to parameters and delegates
    {
        Debug.Log(name + "Button trigger event");
    } 
    
    private void OnDisable()  // when the current script is not available (not activated)
    {
        EasyButton.On_ButtonDown -= Show; // Cancel the event
    }
    
    private void OnDestroy()     // It is better to write this for rigor, as above{ EasyButton.On_ButtonDown -= Show; }}Copy the code

Using EasyJoystick, move the object

The code shown above

public class Easyjoy : MonoBehaviour 
{
    float vx;
    float vy;

    void Start () 
    {
        EasyJoystick.On_JoystickMove += Move;   // Register movement events
        EasyJoystick.On_JoystickMoveEnd += End; // Register stop event
    }
	

    void Update ()
    {
        this.gameObject.transform.Translate(new Vector3(vx,0,vy)); 
    }

    void Move(MovingJoystick mo)    // Custom move method
    {
        vx = mo.joystickAxis.x;
        vy = mo.joystickAxis.y;
    }
    void End(MovingJoystick mo)     // Custom stop method
    {
        vx = vy = 0; }}Copy the code