Hi, i have a problem with adding GameManager with hierarchy to a prefab which isnt in hierarchy, its create while game. When i created prefab with GameManager i can add this, but its impossible to have two gamemanager :>
Since Prefabs are defined outside/independent of scenes, they cannot be directly connected with something in the scene before the game starts.
Singletons are usually the way to go, but be careful to not overuse that pattern. In general try to minimize dependencies between scripts.
If you need something like a data storage, look into ScriptableObjects. Those are defined similar to prefabs outside of the scene and thus can be referenced in a prefab like any other asset.
Am not sure what you mean by “its impossible to have two gamemanager”.
Just to interrupt…Thanks DragonCoder for your explanation of ScriptableObjects. They are more or less hidden away in Unity and not explained very well. Good on you for bringing this up.
I have to use prefab becuase i maked popup damage information with animation create with click. In this prefab is script which have OnDestroy event and in this event is money text which set money + amount.
When player click on the “monster” instantiate prefab popup money animate to money text and when it’s destroy by time its set text in other script which is on the GameObject gameManager