store increment info on true 'without losing' it when bool returns false.

I’ve just started learning programming and managed to script pong. This is the ricochet script for the ball. I want to add +1 to speed when the ball hits a paddle (Hitpad) but I lose the +1 when the bool returns to false. I thought this would be easy after everything but it’s doing my head in. Please help.

I’ve tried ++ operator and even calling a method inside update to increment. But no matter what i put under bool, it won’t count anymore when it turns false. So the information isn’t stored seperately/independently from the bool. Is there maybe a way to increment the variable speed and then cut the connection it has from the bool? Or any other solution? Adding +1 to speed doesn’t work in the collision method since it only gets called once and won’t get stored.

I want to add 1 to speed every time the collider hits. Really trying to get this one…

Here’s the script:

C#

public class DotScript : MonoBehaviour { 

	public bool Hitwall;
	public bool Hitpad;
	public float speed;

	void FixedUpdate ()

	{
		speed = 4;

		speed = speed * Time.deltaTime;

		transform.Translate (speed, speed, 0); 

		//if hit is true this statement enables, if hit is false it disables.

		if (Hitwall) 
			transform.Translate (0, -speed * 2, 0);
		
		if (Hitpad) 
		{
			transform.Translate (-speed * 2, 0, 0);
			speed = speed + 1; //problem: when bool is false the increment is gone with it.
		}
	}
	

	void OnCollisionEnter (Collision hit)

	{

		if (hit.gameObject.tag == "wall") 
			Hitwall = !Hitwall;	

		if (hit.gameObject.tag == "paddle") 
			Hitpad = !Hitpad;
	}
}      

Any critique or tips are much appreciated btw.

I just figured it out…

speed = speed * Time.deltaTime;

Doesn’t work cause:

deltatime with 60fps is 0.016 * 4 (speed) = 0.064 = speed

causing speed to attain a new value. Being in the update function; the calculation runs again:

(speed) 0.064 * (speed x deltatime) 0.016 = 0.001024 = speed

0.001024 * 0.016 = 0.000016384 = speed

This exponentially goes on as a quadratic function until there are too many zeroes for a float, resulting in a value of 0 for the float speed.