how to move player with getAxis and UI buttons

pretty self explanatory title but lets expand a little so i now have a few UI buttons left right and jump but my players left and right motion is controlled through Input.GetAxis("Horizontal") so im wondering if i can split this somehow into left and right this is the block

moveHorizontal = Input.GetAxis("Horizontal");
            Vector3 movement = new Vector3(moveHorizontal, 0, 0);
            rb.AddForce(movement * speed);

so i need to check if moveHorizontal is < or > 0 and then move left or right but i dont know how you can move left or right using getAxis or if i can swap it to something like getKey and still keep the same speed and such, heres how im passing the code to my UI button, someone from here helped me with this,

public void Move(string mDir)
{
    if (mDir == "left")
    {

        moveHorizontal = Input.GetAxis("Horizontal");
        Vector3 movement = new Vector3(moveHorizontal, 0, 0);
        rb.AddForce(movement * speed);
        animator.SetFloat("rollLeft", 0);
        animator.SetFloat("rollRight", 2);
        jumpingDirection = false;
        if (moveHorizontal < 0)
        {
           
        }

    }
    else if (mDir == "right")
    {
       
        moveHorizontal = Input.GetAxis("Horizontal");
        Vector3 movement = new Vector3(moveHorizontal, 0, 0);
        rb.AddForce(movement * speed);
        animator.SetFloat("rollRight", 0);
        animator.SetFloat("rollLeft", 2);
        jumpingDirection = true;
        if (moveHorizontal > 0)
        {
           
        }

    }
    else if (mDir == "jump")
    {
        doMovement = true;
        isGrounded = false;
        rb.AddForce(0, jumpSpeed, 0);
        source.PlayOneShot(jumpNoise, 1f);

        if (jumpingDirection == true)
        {
            animator.SetFloat("jumpLeft", 0);
            animator.SetFloat("jumpRight", 2);
        }
        else if (jumpingDirection == false)
        {
            animator.SetFloat("jumpRight", 0);
            animator.SetFloat("jumpLeft", 2);
        }

    }

so obviously as it stands left and right do nothing but change the animation and that works but theres obviously no movement but jump works fine
any and all feedback welcome

i am also looking for same solution. to GetAxis Horizontal by UI button in unity. But still no solution found.

It seems like you already have something that works, but here’s another answer anyway.

You can achieve something similar to Input.GetAxis ("whatever") with:

using UnityEngine;
using UnityEngine.UI;

public class UIButtonInputAxis : MonoBehaviour {
    private float value;
    public float Value { // Readonly for security
        get {
            return value;
        }
    }
    public Button PositiveButton;
    public Button NegativeButton;
    public void UpdateAxisValue (int v) {
        value += v;
    }
}

Attach the UIButtonInputAxis to an empty GameObject in your scene (You’ll need one of these per axis you want to set up).

You’ll need two buttons, and each one should have an “Event Trigger” component with both “Pointer Down” and “Pointer Up” events added.

On the “Positive” button’s “Pointer Down” event, assign the UIButtonInputAxis object, and call the UpdateAxisValue function with whatever positive value you want (1, most likely). On the “Pointer Up” event, do the same thing, but with -1.

Do the exact same thing on the “Negative” button’s events, but with the value’s swapped (-1 on “Pointer Down”, +1 on “Pointer Up”).

When this is set up, it can be used as such:

using UnityEngine;
using UnityEngine.UI;
public class UIButtonInputAxisExample : MonoBehaviour {
    public UIButtonInputAxis inputAxis;
    public Slider example; // Slider with range set from -1 to 1
    void Update () {
        example.value = inputAxis.Value;
	}
}

Just hook up the UIButtonInputAxis in the inspector, and you’re good to go.