- Home /
Toggling a purchased gameobject on and off in inventory
I am trying to do some in game character customization and I'm running into a big problem. I have a game object the user wants to buy/equip (lets call it helmet) in the shop, the user goes to the shop and if they have enough coins they buy the helmet and i run this code:
if (frogHelmetSold == 1)
{
frogHelmet.SetActive (true);
frogHelmetLocker.SetActive (true);
}
else
{
frogHelmet.SetActive (false);
frogHelmetLocker.SetActive (false);
}
This will purchase the helmet, equip it and put it in the users locker and is working fine. BUT when i try to toggle the helmet on and off with the frogHelmetLocker button, like this:
public void toggleFrogHelmet()
{
frogHelmet.SetActive (!frogHelmet.activeSelf);
}
When debugging the value for activeSelf is always false. Which at least should mean the Helmet turns off but it doesn't.
edit: frogHelmetSold must be an int so i can use PlayerPrefs
Answer by logicandchaos · Jan 31, 2020 at 03:22 AM
It might be your frogHelmetSold variable, if it is not equal to 1 than frogHelmet will always be false. If you can only buy the helmet once you could make it a bool than you could go: frogHelmet.SetActive (frogHelmetSold); frogHelmetLocker.SetActive (frogHelmetSold); instead of having ifs.
Your answer
Follow this Question
Related Questions
Toggling through music 1 Answer
Is there a toggle for snap to grid? 10 Answers
Press key to toggle pointlight on/off 1 Answer
GUI Button selected changes color and stays until another button is clicked 1 Answer
Particle System Toggle in Custom editor 3 Answers