Transferring a Variable to Another Scene

Is there a way to send the value of a variable from one scene to another? I want to make it so you can set the difficultly on the main menu and that difficultly will set a multiplier for the enemies’ hitpoints (For example easy = 0.5, normal = 1, and hard = 2), but I don’t know how to access the variable from another scene or if that’s even possible. Could someone point me in the right direction?

There are a few ways you can do this. Player Prefs for example would be an easy way.

You could create a singleton. A singleton is basically a game object with a script attached, which has DontDestroyOnLoad() active. This means it will stay around even after you load a new level.

The other thing a singleton does is delete any other copies of the singleton, in case you have the singleton placed in multiple levels but only want one at a time. During the Awake() function, do a search for any other copies of the singleton. If the script finds one, then it deletes itself, leaving only the one that was already there.

Just one of many ways to do it.

Player Prefs, Singletons… , Static vars (globals) :wink:

Thanks for all the suggestions.