Add force when button is pressed

I want to make my cube move right when u press button until you release it.
When I press button called RightButton nothing happens.

    public Rigidbody rb;

    public float forwardForce = 2000f;
    public float sideForce = 200f;

    void FixedUpdate()
    {
        rb.AddForce(0, 0, forwardForce * Time.deltaTime);

        if (Input.GetButton("RightButton"))
        {
            rb.AddForce(sideForce * Time.deltaTime, 0, 0, ForceMode.VelocityChange);
        }
    }

Here’s screen shot of this button:

I’m new user of unity so don’t flame if i’m doing something wrong

the “Button” you added that was not from the UI menu


110108-rr.png

then you say when pressed you increase the speed

public void Addforce()
{
    rb.AddForce(sideForce * Time.deltaTime, 0, 0, ForceMode.VelocityChange);
}

hope this helped

@jman12EX
I did what u said, but there’s one problem it adds force only once when I click, but I want it to add force every “Time.deltaTime”.

public Rigidbody rb;

public float forwardForce = 2000f;
public float sideForce = 200f;

void FixedUpdate()
{
    rb.AddForce(0, 0, forwardForce * Time.deltaTime);
}

public void Addforce()
{
    rb.AddForce(sideForce * Time.deltaTime, 0, 0, ForceMode.VelocityChange);
}

Now button was added from UI-Button
110124-szkic.png
Am I doing something wrong again?

Or meaby I should do this as before but add this button to Edit-Project Settings-Input ?

HEEL YEA I FOUND A SOLUTION. Here’s the code:

    bool moveRight;
    public Rigidbody rb;

    public float forwardForce = 2000f;
    public float sideForce = 200f;

    // Update is called once per frame
    void FixedUpdate()
    {
        // Adding force to player
        rb.AddForce(0, 0, forwardForce * Time.deltaTime);


        if (moveRight == true)
        {
            rb.AddForce(sideForce * Time.deltaTime, 0, 0, ForceMode.VelocityChange);
        } else
        {
            rb.AddForce(0, 0, 0, 0);
        }
    }

    public void onPress()
    {
        
        moveRight = true;
    }

    public void onRelease()
    {
        
        moveRight = false;
    }