Hello everyone, I'm really new to Unity and have a simple/silly question. I have a game coded into a scene. The game has difficulty levels (easy, medium, hard). I want to load the scene with the proper difficulty level when the user clicks a button (already coded). I just don't know how to "pass" the difficulty level into the scene. How do I get the difficulty level variable (int or string doesn't matter to me) accessible to the game scene? Thanks for your help.
#Loading scene with different levels
1 messages · Page 1 of 1 (latest)
you'd need something to provide the value, and something to receive the value, and they need to coexist for some period of time
you could have for example
- a DDOL provider, and the level can read that
- a DDOL provider that gets something from the level and passes the value in
- additive loading, get something from the level, pass the value in, and then unload whatever needs to be unloaded
- an additive scene with a singleton, and the level can read that
etc, combine as needed
Also look into Scriptable Objects
and one more soloution: https://docs.unity3d.com/6000.3/Documentation/ScriptReference/PlayerPrefs.html
If you're really new to unity, the simplest approach might be to create a script that does not derive from MonoBehaviour, and has a static variable on it called CurrentDifficultyLevel or something like that.
Like this
public static class DifficultyManager
{
public static int CurrentDifficultyLevel = 1;
}```
and then you can access it from anywhere by doing DifficultyManager.CurrentDifficultyLevel
it's not exactly proper code if you're doing things professionally, but for a beginner this will solve your problem, and will set you on a really good track of discovery down the road as you discover the limitations (and better versions) of such a system
You can also look into DontDestroyOnLoad but doing that requires either something called a "singleton", or using improper functions like Object.Find which you should almost never use, and we're kinda doing something close enough to a singleton in the first one anyway. No need to attach it to an object for no reason, unless you want to edit the variables in the inspector.
Could also use Remote Config if you want to do tuning without new versions