After reading and trying many different examples, I am still stuck with this fairly simple problem on getting a score from one level to the next in Unity.
I have a
The DontDestroyOnLoad method is callable on an object, not on a single variable. It represents the best possible approach for a value of that kind, that needs to be "exported" from your actual scene.
However, you can also use PlayerPrefs. They are intended for informations at a "higher" level of persistency, like flags for unlocked levels, final scores for a ranking system, or attributes of a customizable character. That's why the DontDestroyOnLoad way is better suited (for your "temporary" score), but you can use this one also. Basically, PlayerPrefs are information stored in the registry of your operative system.
Before exiting from the actual scene, save the score this way:
PlayerPrefs.SetInt("Player Score", finalScore);
And, when next scene starts, initialize score's variable by retrieving that information:
finalScore = PlayerPrefs.GetInt("Player Score");
(here a similar post)
Someone else said, and I shamelessly quote, use a static variable for your data in a C# class, and there you go...
(Still I'd prefer to pass parameters to LoadLevel itself, but that's another story)