How do I create a static bool?
I have a menu screen with three buttons, start night one (intractable), start night two (disabled until bool is TRUE), and quit (intractable). I simply want, after the player finishes the game (after 530 seconds) set the bool to TRUE and redirect the player back to the menu, where then they can continue and play night two because it will be enabled from the bool.
There are a few things I have no idea how to do:
- Create the static bool, and have it become true after 530 seconds
- Have the night two button use the bool to determine enabled/disabled state
- Redirect player to menu after 530 seconds
Please and thanks for any help! Please use javascript.
I was able to get the night 2 button to activate after the night 1 button is pressed. How do I get the player to go back to the menu in the same session after 530 seconds? Thanks
Answer by EmHuynh · Feb 16, 2016 at 01:55 AM
Hello, @LeoKane. Nicely done, you took care of those buttons. Here are some codes to help you get an idea of what you could do to achieve your goal (for your menu).
// The flag to ensure we only attempt to the load the menu once.
bool menuCoroutineStarted = false;
// A coroutine to load the menu after waiting for 530 seconds.
// For testing purposes, that you should lower it so we can
// quickly test things out.
IEnumerator BackToTheMenu()
{
yield return new WaitForSeconds( 10 );
// Load the menu scene.
SceneManager.LoadScene( "Menu", LoadSceneMode.Single );
}
void Update()
{
if( Input.GetKeyUp( KeyCode.Space ) && menuCoroutineStarted == false ) {
menuCoroutineStarted = true;
// Call StartCoroutine to start BackToTheMenu.
StartCoroutine( BackToTheMenu() );
}
}
It works mostly. I made it into a javascript, right? But a lot of the script is obsolete. The only two errors though are missing semi-colons, could you help?