How can I change a function in a script within a different scene

I have a 2D car game in which I have a gasmeter. The gasmeter has a timer on it. When the timer runs out you go to a different scene: the garage. I want to make this garage so that I can upgrade the fuel there. Which means that when you upgrade your fuel/gastank, the timer should take longer to run out. What is the best way to do this?

Hi there, and welcome to Unity Answers.

You cannot alter a method’s functionality once it’s been compiled. The better way to do it would be to store the Fuel value as a public variable or property so you can just change it by calling YourObject.MaxFuel = whatever (or if it’s being changed in YourObject directly, just MaxFuel = Whatever will suffice).

The other thing to take note of is that since the scene changes, if that information isn’t stored externally to the scene, via a static object or variable (or other means), then that information will be lost when the scene changes.

Hope this helps!