2D Rigidbody Move with Button dont move.

I have writing this Script:

using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.SceneManagement;
using UnityEngine.UI;

public class PlayerController : MonoBehaviour
{
    public Rigidbody2D rb2D;
    
    public bool grounded = true;

    /*public Button moveLeftButton;
    public Button moveRightButton;
    public Button jumpButton;*/

    private void OnTriggerStay2D(Collider2D collision)
    {
        grounded = true;
    }

    private void OnTriggerEnter2D(Collider2D collision)
    {
        grounded = true;
    }
    private void OnTriggerExit2D(Collider2D collision)
    {
        grounded = false;
    }

    void Start()
    {
        
    }
    public List<RuntimeAnimatorController> skins;

    void Update()
    {
        rb2D.velocity = new Vector2(0, rb2D.velocity.y);
        
        if (Input.GetKey(KeyCode.RightArrow))
        {
            RightMove();
        }
        
        
        if (Input.GetKey(KeyCode.LeftArrow))
        {
            LeftMove();
        }
        
        if (Input.GetKeyDown(KeyCode.Space))
        {
            Jump();
        }
        
        if (transform.position.y < -8.85)
        {
            SceneManager.LoadScene(SceneManager.GetActiveScene().buildIndex);
        }
    }

    public void RightMove()
    {
        rb2D.velocity = new Vector2(10, rb2D.velocity.y);

    }

    public void LeftMove()
    {
        rb2D.velocity = new Vector2(-10, rb2D.velocity.y);
    }

    public void Jump()
    {
        if (grounded)
        {
            rb2D.AddForce(new Vector2(0, 600));
        }
    }

    /*public void ButtonMoves()
    {
        moveLeftButton.onClick.AddListener(LeftMove);
        moveRightButton.onClick.AddListener(RightMove);
        jumpButton.onClick.AddListener(Jump);
    }*/
}

and access it to the button:
203728-screenshot-2023-01-09-154442.png

but it still doesnt works.
Can anyone Helps with that?

The problem you have here is the order of execution and/or the fact that the OnClick is probably just triggering for one frame.

Then in line 39 you reset the x-velocity to zero again. So if the callback is evaluated before Update you directly invalidate the effect or if it is evaluated afterwards, you just set the velocity for one frame.

There are user-crated solutions to detect if a UI Button is being pressed over multiple frames. (Keywords: Button OnRelease PointerEvent) see for example this stack overflow thread here.
When you use this you can properly set the velocity on Button Press start and set it to zero on button release event.