dima dima - 2 months ago 7
C# Question

How to check if game was started once

In my game I have main menu with the "New game" button. I need to check, if I press this button first time in this game session like:

I start new game with this button (press first time), then from the game I come back to the main menu, then I press this button again (press not first time).

public void ButtonNewGame()
{
if() // if the game was started once
{
GameObject gameMAnagerObj = GameObject.FindGameObjectWithTag("GameManager");
GameManager gameManagerScript = gameMAnagerObj.GetComponent<GameManager>();
gameManagerScript.currentActNumber = 0;
act_0.stepNumber = 0;
}
SceneManager.LoadScene("Casino");
}

Answer
public static bool IsStartedFirstTime = false;

public void ButtonNewGame()
{
    if(IsStartedFirstTime == false) // if the game was started once
    {
        IsStartedFirstTime = true;
        //Logic on first time run 
        //return;  //depending on your intent, you might wish to return or not!
    }
    if(IsStartedFirstTime)
        // your logic that happens if it is already started      
}