Reputation: 526
i have 3 button i want when i click button 1, hide that button and show all button with PlayerPrefs, and when i click button 2, hide that button and show all button with PlayerPrefs i test my code but work with button 2 only
void Start()
{
if (PlayerPrefs.GetInt("Button1") == 1)
{
object1.gameObject.SetActive(false);
object2.gameObject.SetActive(true);
}
else if (PlayerPrefs.GetInt("Button1") == 0)
{
object1.gameObject.SetActive(false);
object2.gameObject.SetActive(true);
}
if (PlayerPrefs.GetInt("Button2") == 1)
{
object2.gameObject.SetActive(false);
object1.gameObject.SetActive(true);
}
else if (PlayerPrefs.GetInt("Button2") == 0)
{
object1.gameObject.SetActive(true);
object2.gameObject.SetActive(true);
}
}
public void whenclickbutton1()
{
object2.gameObject.SetActive(true);
PlayerPrefs.SetInt("Button1", 1); PlayerPrefs.SetInt("Button2", 0);
PlayerPrefs.Save();
}
public void whenclickbutton2()
{
object1.gameObject.SetActive(true);
PlayerPrefs.SetInt("Button2", 1); PlayerPrefs.SetInt("Button1", 0);
PlayerPrefs.Save();
}
Upvotes: 1
Views: 741
Reputation: 3108
So, you want to hide the clicked button, and show the rest? Only having 1 playerpref would work then, containing the hidden button?
void Start()
{
HideAndShowButtons();
}
void HideAndShowButtons()
{
object1.gameObject.SetActive(PlayerPrefs.GetInt("HiddenButton") != 1);
object2.gameObject.SetActive(PlayerPrefs.GetInt("HiddenButton") != 2);
}
public void whenclickbutton1()
{
PlayerPrefs.SetInt("HiddenButton", 1);
PlayerPrefs.Save();
HideAndShowButtons();
}
public void whenclickbutton2()
{
PlayerPrefs.SetInt("HiddenButton", 2);
PlayerPrefs.Save();
HideAndShowButtons();
}
Upvotes: 4