I can't get my speed to go a little bit faster very slowly every second

I’m trying to get my character to run a little bit faster every second but slowly getting faster but for some reason it goes until a certain point and goes back and fourth between 2.0, 2.24 and 2.25 in stead of going on until 15. Is there any way to increase the movement speed by 0.05 every second. Here is the code

    public static float moveSpeed;
    public static float movementSpeed;


    // Use this for initialization
    void Start() {


    }

    // Update is called once per frame
    void Update() {

        GetComponent<Rigidbody>().velocity = new Vector3(horizVel, 0, movementSpeed);

        if (moveSpeed < 15)
        {
            moveSpeed += 0.05f;

        }

        movementSpeed = moveSpeed *Time.deltaTime + 4 ;

        Debug.Log(movementSpeed);

The problem here is fairly straightforward:

You’re pre-calculating a value which doesn’t need to be calculated ahead of time, and multiplying it by the wrong value at the wrong time.

moveSpeed is your value for your current speed, which you’re feeding into your Rigidbody’s Velocity as movementSpeed. Additionally, Update() really isn’t the ideal place to update Rigidbody data, because the results won’t have the timing you intend for them.

Based on the multiplication you’re applying, I will assume (for the purposes of this answer) that you want moveSpeed to increase by 0.05 per second rather than 0.05 per frame.

With this in mind, I propose the following:

// If desired, allow the maximum speed to be adjusted. This may help in numerous ways in the long term.
public float maximumSpeed = 19.0f;

// Acceleration per second
public float accPerSec = 0.05f;

Rigidbody rb;

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

void Update()
{
	if(moveSpeed < maximumSpeed)
	{
		moveSpeed += accPerSec * Time.deltaTime;
		if(moveSpeed > maximumSpeed)
		{
			moveSpeed = maximumSpeed;
		}
	}
}

void FixedUpdate()
{
	rb.velocity = new Vector3(horizVel, 0, moveSpeed);
}

First, I combined a few values. By moving the Time.deltaTime multiplication and setting a starting value of 4 to moveSpeed, I cut out the transformations that were applied and eliminated the need for the movementSpeed variable.

Second, now that the moveSpeed increases are no longer a consistent value, I put a check inside the initial if statement to check if you went over the maximum, so that it will only be checked whenever the speed does increase.

Finally, I moved the Rigidbody calls into their own variable, since that improves efficiency considerably compared to calling GetComponent<> every frame. Then, by moving the velocity changes into FixedUpdate(), they only get called on a Physics frame, rather than attempting to change velocity during every rendering frame, which may be faster or slower than the physics updates are being performed.