# How to make the whole game wait until some new feature at beginning is finished? In Unity

I have been working on a driving game and its almost finished. I'm just trying to add some polishing touches. Ironically this part im stuck on now would not have been any issue at all in purely code based frameworks i used before (LibGDX/Xna) because I could just make a boolean that's called ReadyToPlay or something and just put that around all the code i want to wait to start.

I've made a secondary camera which rotates around the players car, it works fine but my problem is that the GUI is also already loading AND the race start countdown occurs still whilst the camera is still spinning.

I'm not sure in Unity how to go about stopping that to allow the time for the camera to spin.

One idea I have to fix this (i'm checking first because this doesnt seem right to me) is to use the yield routine in the GUI loading script and tell it exactly how many seconds the camera is going to spin for. I'd rather have just have the camera detected when its done a full spin and then make a boolean true, or trigger another method to start the game properly.

I promise I have done some research trying to find ways but the only thing i can find except yield, is Monobehaviour.Invoke but the invoke method still requires me to specify the time.

The whole strategy for yield or invoke feels wrong to me. I guess my main problem is that the code is spread over a few scripts, instead of being funneled thru a main.cs and then gameManager.cs etc etc so theres no way (that I know) to break the chain higher up. I'd have to add bools to each script to say isLuxuryCameraAlive and that still seems wrong to me as I might have 5-10 scripts and have to also section of bits of code in each script.

How would you experienced programmers attack this issue??

Thank you!!

in purely code based frameworks i used before (LibGDX/Xna) because I could just make a boolean that's called ReadyToPlay or something and just put that around all the code i want to wait to start.

You can still do pretty much the same thing in Unity, but the difference is that elements laid out in the editor already exist (ie. they don't need to be created from code) so you need to hide them first. Just make controller scripts that set gameObject.SetActive(false) in Awake(), then set gameObject.SetActive(true) later.

Exactly how they are triggered later can vary depending on your code architecture, but it sounds like you want a central Controller that hides and shows multiple objects linked to it, and call the one ShowMultiple() method on that controller from the script that spins the camera.

• thank you . I like both of the suggested solutions . I am going back into Unity now to see if I can get it all working. Thanks for your help – Big T Larrity Jul 22 '17 at 21:44
• In the end i have chosen this approach. As I think that all i need to do is set one script in the UI to false and that should get the desired effect for me. It was great to read about the static class though as that would also be useful in so many ways. Thanks for taking the time out to help me guys. – Big T Larrity Jul 22 '17 at 21:48

You can create a "global-ish" class with a static member eg: public static bool IsReadyToPlay() and another static member to clear/set the boolean variable.

Then check for that function GameGlobal::IsReadyToPlay() to return true in the few relevant scripts.

Setting objects active/inactive will show/hide them which is probably not what you want.

Setting individual components to active/inactive can be messy and error-prone.

A static bool variable could do the job too but being able to put a breakpoint or Debug.Log in SetReadyToPlay is often a time saver when debugging.

• thank you . I like both of the suggested solutions . I am going back into Unity now to see if I can get it all working. Thanks for your help – Big T Larrity Jul 22 '17 at 21:44