android - C# PlayerPrefs.Save() -


i have 2 methods switch between accelerometer , touch controller type. doesn't save preferences. help?

public void inputchoicefalse() {     if (playerprefs.haskey("playerchoice"))     {         playerprefs.setint("playerchoice", playerchoice ? 0:1);         playerchoice = false;         debug.log("false "+playerchoice);         value = 0;         playerprefs.save();     }  }  public void inputchoicetrue() {     if (playerprefs.haskey("playerchoice"))     {         playerprefs.setint("playerchoice", playerchoice ? 0 : 1);         playerchoice = true;         debug.log("true "+playerchoice);         value = 1;         playerprefs.save();     } } 

why checking if exist, maybe player prefer not exist not execute @ all? not know why have methods doing same thing. recommend change code.

public void inputchoice(bool choice ) {     playerchoice = choice;     value = playerchoice ? 0:1;     playerprefs.setint("playerchoice",value);      playerprefs.save(); } 

remember dry(don't repeat yourself) rule. code easier maintain.