I
I
Ivan Spasov2021-10-09 11:30:01
Unity
Ivan Spasov, 2021-10-09 11:30:01

Where to store the state with parameters for the scene?

Example:
Where to store the GameState.Pause state to keep track of it in scripts and not do anything if the player is in the menu/pause ?
Where to store the player settings, keys, mouse sense, sound volume, etc.?
Where to store parameters, movement speed, initial amount of hp, etc.?

I saw various kinds of GameManager as an object on the stage, but it will turn out to be some kind of monster, if you put everything into it, please tell me what approaches are usually used?

Answer the question

In order to leave comments, you need to log in

2 answer(s)
A
Andrey Boronnikov, 2021-10-10
@spasiboivanu

The question of the pause is the question of the architecture of the project.
The simplest is to have a static variable "GameController.IsPause" or something like that. But here a bunch of bugs can pop up if you pull from a bunch of different places. A smarter approach would be a Singleton , which should also be sent the object that caused the pause to manage collisions, when several objects pause, and one of them releases. Those. so that there is no situation when 2 objects consider that a pause is needed, but some 3rd reset this pause. Through the Singleton class, you can have access to all objects that want to pause and determine their importance / priority. But in general, singletons are also not a good practice now, but for a start - that's it.
And the question of storing mob parameters and settings isStaticData - data that is filled in 1 time and is no longer touched in the gameplay itself. ScriptableObjects are used for this . Those. such habits are created with data that you fill in as monobehs in prefabs, and then send them to MonoBehaviours, from where you read the data and set the required parameters.

L
Loli E1ON, 2021-10-09
@E1ON

https://docs.unity3d.com/ScriptReference/PlayerPre...

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question