Answer the question
In order to leave comments, you need to log in
Does the unit have global variables?
I decided to see what kind of animal this unit is, created a scene, a character, dynamic spawn of objects, etc., but there was a need for global variables. How to implement them and in general is this the right way? In variables I want to store parameters such as speed, state of the person, etc. => I need to have access to them from any script and possibly edit them. How to implement it correctly?
Answer the question
In order to leave comments, you need to log in
There are no global variables in the unit, or rather in c#. There are static variables and constants that can be used to store global information, but it's highly doubtful that you need truly global accessibility. Most likely, you have several classes that, due to improper separation of duties, are forced to crawl into each other to synchronize state. This can only be solved by reorganizing the code, global variables and singletons will only aggravate the matter. In the context of a unit, the dependency injection
technique works well for resolving dependencies , which is implemented in many frameworks, for example, in Zenject . In addition, the unit has a ScriptableObject, which is very convenient for storing configs, makes it easy to transfer them between classes and edit them at runtime. I think these two things should be enough to get you started, the rest will come with practice.
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question