How would I be able to easily reset a variable

I am making a truck driving game. Which has a fuel gauge.

What would be the coding to make the fuel reset if the player were to lose the game.

You’re gonna have to also save its original value. To make it even easier, simply set the starting level to what you want in the editor or the start function, and then set the ‘max gauge’ to whatever the current fuel level is.

i.e.

public float fuel;
private float maxFuel;

void Start() {
    fuel = 100;       //Or set it in the editor!
    maxFuel = fuel;
}

void loseGame() {
    fuel = maxFuel;
}

If you are 100% sure you will never change the starting amount of fuel again you can always just hardcode it in the start and restart places. Doing it this way means if you want to change the starting fuel amount you will need to change it in both places rather than 1 for the above proposed solution

:slight_smile:

That coding looks good. However, when I use it in my script I get these two errors
attached to this message is a screenshot of the following errors.13440-errors.jpg