Home>

We are making action games using the Unity library.

Unity 2D Platformer Controller
https://github.com/cjddmut/Unity-2D-Platformer-Controller

There is a function that can move the keyboard here, and I want to prepare a button with uGUI and perform the same operation.
I implemented the following as a reference to PlayerController2D.cs.

I jumped but couldn't move left or right.
With the script below, it is not possible to move without changing the direction of the character.

If i have ever used this library, would you give some advice?
uGUI buttons do not register events to the default ones,
Pressing and holding is detected using EventTrigger.

private void Update () {
    // move left
    if (leftFlag&&! rightFlag) {
        MoveLeft ();
    }
    // move right
    if (rightFlag&&! leftFlag) {
        MoveRight ();
    }
    Debug.Log (leftFlag);
}
private void MoveLeft () {
    motor.normalizedXMovement = -1;
}
private void MoveRight () {
    motor.normalizedXMovement = 1;
}
public void PressDownLeft () {
    leftFlag = true;
}
public void PressUpLeft () {
    leftFlag = false;
}
public void PressDownRight () {
    rightFlag = true;
}
public void PressUpRight () {
    rightFlag = false;
}
public void Jump () {
    motor.Jump ();
    motor.DisableRestrictedArea ();
}