在我的游戏中,我有主菜单和“新游戏”按钮。如果我在这个游戏会话中第一次按下此按钮,我需要检查:
我用这个按钮开始新游戏(按第一次),然后从游戏中我回到主菜单,然后我再次按下此按钮(不按第一次)。
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");
}
答案 0 :(得分:4)
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
}