Game Development Stack Exchange is a question and answer site for professional and independent game developers. It only takes a minute to sign up.
Sign up to join this community
Anybody can ask a question
Anybody can answer
The best answers are voted up and rise to the top
I have a script that is made to run when the game is loading.
That script set the resolutions, fullscreen, and loads other screen and important settings and it applies them.
I have the script attached to a gameObject in the main screen that have some game and scene scripts.
The problem is that everytime that you return to the main scene, that script runs again and cause several bugs.
So, there is a way to run a script only at game startup?
I wouldn’t know a better way than the way you already do: By attaching it to a gameObject in your first scene and putting your setup code in
As possible workarounds for the problems you encounter I would recommend:
- Create an initialization scene which runs even before your main screen. The purpose of that scene is to run any initialization code and then load your main screen scene. You can also use that scene as a loading screen for the game.
- Add a variable
private static bool initializedto your initialization script. Then wrap the whole code of its Start method into
if (!initialized)and end that code with
initialized = true.