I have a menu with a button called btnNewGame. I have attached a C# script called MainMenu.cs to my camera and would like to execute a function that checks if there is an existing PlayerPrefs entry called “EXISTINGGAME” and if so, hide the menu button object, btnNewGame. The opposite logic would apply for btnLoadGame (but not there yet).
My question is, how do I set the new UI button to be inactive if the following function is called:
public void CheckifGameExists(){
if(PlayerPrefs.HasKey("EXISTINGGAME")) {
if(PlayerPrefs.GetString("EXISTINGGAME") == "Yes"){
Debug.Log("This is an existing player");
//hide new game button???
}else if(PlayerPrefs.GetString("EXISTINGGAME") != "Yes"){
Debug.Log("This is new player");
//hide load game button???
}
}
}
I am guessing I need to call CheckifGameExists in void Awake, or is there a better way?