Why don't this code work with a if statement? but does without it???

Strange if I remove the if statement it works…but I want to control the force when the button is pressed and not always. Please advise thank you.

using UnityEngine;

public class AddForce : MonoBehaviour
{
    public float thrust;
    public Rigidbody rb;

    void Start()
    {
        rb = GetComponent<Rigidbody>();
    }

    void Update()
    {
        if (Input.GetKey(KeyCode.Keypad5))
       
        rb.AddRelativeForce(0, thrust, 0, ForceMode.Impulse);



    }
}

It’s working for me.
Using the number pad ‘5’ key? :slight_smile:

For 1 line after the ‘if’ statement, brackets aren’t required…
Also, spacing (whitespace) is irrelevant in this context (no need to make the statement on the very next line if you don’t want to, though you usually would as it makes more sense visually, I’d say).