Changing GetKey to a button UI

Hello I am new to unity and I need help changing my Input.GetKey to a button that I press instead of a key. I know how to make a button UI and add a script to it I just dont know how to change the GetKey to a button press. This is y ch erector movement script btw:

using UnityEngine;

public class PlayerMovement : MonoBehaviour
{

    public Rigidbody rb;

    public float forwardForce = 2000f;
    public float sidewaysForce = 500f;

  
    void FixedUpdate()
    {
        // Add a forward force
        rb.AddForce(0, 0, forwardForce * Time.deltaTime);
  
        if ( Input.GetKey("d") )
        {
            rb.AddForce(sidewaysForce * Time.deltaTime, 0, 0, ForceMode.VelocityChange);
        }
        if (Input.GetKey("a"))
        {
            rb.AddForce(-sidewaysForce * Time.deltaTime, 0, 0, ForceMode.VelocityChange);
        }

        if (rb.position.y < -1f)
        {
            FindObjectOfType<GameManager>().EndGame();
        }
    }
}

Instead of having the if statement immediately drive the force thingy, put the input into a temporary boolean variable, which will allow you to collect multiple sources of input, and THEN go act on it.

The way it should flow is this:

  • clear boolean inputs (one boolean for each input axis you want)
  • update keyboard input: if key down, set appropriate boolean true
  • read from button: check button state and see if it is down or up, set appropriate boolean true
  • now act on the booleans (if true, add the forces)