How to save a variable

I am new to unity and was working on a game. I have code to have the players health set during decleration. When I switch scenes I want this health variable to persist. How could I go about making something like that.

Here is Unity Blog post on this topic:

And some tutorial how to save game state using JSON

I would recommend looking at PlayerPrefs - Unity - Scripting API: PlayerPrefs - there is one thing called PlayerPrefs.Save(), which may be exactly what you might be looking for, then you can use PlayerPrefs.GetFloat() or PlayerPrefs.GetInt() to get the value.

BEWARE PLAYER PREFS CAN BE VERY RISKY THOUGH!!!