How to increase and decrease speed gradually?

I have a Rigidbody attached to car, which is controlled by the player. What I need is a code to make the car gain speed gradually when “UpArrow” or “W” is pressed and gradually decrease speed when the key is released. I’ve searched online but I have found only code that is not compatible with the latest version of unity.
Thanks in advance!

Uhm… it is actually vey simple. Have a float speed variable. Also have max speed variable. Now, inn update if (Input.GetAxisRaw("Horizontal") > 0f), then add to speed some increment value. Else, remove from speed that increment value. So to add speed you would write speed += increment * Time.deltaTime.

Then to make sure your speed does not exceed limits, after those checks call speed = Mathf.Clamp (speed, 0f, maxSpeed);.

After that it is up to you to use that variable anyhow you like.