- Home /
The question is answered, right answer was accepted
Load Script on Game Start
Hello, so in my game, I have a menu that contains a few variables. In order to access the menu, I have to click a button. But whenever I load the game then click the menu button, the scripts in the menu would load after I click the button. This is a problem because if I need to change variables before first going into this menu, the changes would be overwritten by player prefs. I want the script to load as soon as the game starts. Script Execution Order did not work. Any ideas?
Are you using the menu as a level up type screen. If is it a different scene?
Is there a particular reason you wan this to be inside a new scene? All the level up stuff i do i do with popups and such to keep it simple.
It looks like this is a RTS type game where you click and the menu comes up to buy whatever you want? if that's the case i would just create a game object with the entire menu on it.
Sorry, it's been a long day lol. Sorry, I meant to say yes to the level up/upgrades screen but still exists in the same scene.
Im trying to grasp exactly what is going on i'm kinda distracted. It looks to me like : Scene loads, player selects the item menu comes up . but before menu comes up you are wanting a script to load?
If you want the script to always be loaded then run it at start and set a bool to run it that way the variables are always loaded.
yeah I would try that and I've tried some kind of start thing but in order for the script to read the bool, the script would have to still start before reading the bool.
Answer by as30050273 · Aug 13, 2017 at 09:18 AM
If you need one script's start function run faster than others, try to change it's Start() function to Awake() one.
Or if you have other scripts with awake function, you can add some delay via coroutines or invokes.
I've tried that, but that's not the thing. What's wrong is that the script loads when I click the button ins$$anonymous$$d immediately after the game starts.