- Home /
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, then from the game I come back to the main menu, then I press this button again.
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 by Zodiarc · Oct 07, 2016 at 06:40 AM
The easiest way would be if you create a game folder in the user's documents folder and write a file there. Then every time you click on the button you check for its existence.
You mean to create a variable in that file and check it's value? But then when I close the game, I need to chenge it's value to default. It player will exit with alt + f4, I couldn't do it. I need to set it to default value after start of the game app. How can I check, it the game (not game, but app) was started?
You don't need content. simply check for its existence
string path = System.Environment.GetFolderPath(Environment.SpecialFolder.$$anonymous$$yDocuments) + "/$$anonymous$$yGame";
if(System.IO.File.Exists(path + "/myFile.txt")){
// was started once
} else {
System.IO.Directory.CreateDirectory(path);
System.IO.File.Create(path + "/myFile.txt");
}
EDIT: Ok now I udnerstand the problem. So make an empty scene (or show a company logo on it or something) before the main menu which checks for the file, deletes it and loads the main manu afterwards. Your "Back to main menu" button should load the main menu only and not the scene before.
Your answer
Follow this Question
Related Questions
Multiple Cars not working 1 Answer
Distribute terrain in zones 3 Answers
Smooth movement for Gameobjects switching position 2 Answers
How to create a turn based battle system? 3 Answers
Can't access a Singletons instant. 2 Answers