4
\$\begingroup\$

I would like to have a Main Controller class that should exist in many scenes. I used DontDestroyOnLoad and in runtime an object associated with this class is present in hierarchy. However, how can I use this script if its only visible in runtime? How can I assign the coresponding game object to button if I cant see It until I run the game?

\$\endgroup\$
1
\$\begingroup\$

You could always create a Bootstrap scene that would hold MainController (and anything else that you would like to exist through out the scenes). Keep in mind that bootstrap scene will have to be the first scene to run.

You might want to override Unity's default play button to always load from Bootstrap into whatever scene you're currently on. Here's a nifty little script.

There are also easier solutions, check out the answers on this question.

\$\endgroup\$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.