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
Asked
Viewed
7 times
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?
$endgroup$
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 Start()
.
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 initialized
to your initialization script. Then wrap the whole code of its Start method intoif (!initialized)
and end that code withinitialized = true
.
$endgroup$
lang-cs
