When i click my ui button it changes the text once. then my script wont change the text back when clicked again. Ive tried about everything i can think of so asking for help here. guessing im overtired and missing it. the debug log only prints "1", one time, every time i click the button.
public void HealthBars()
if (PlayerPrefs.GetInt("HealthBars") == 1)
HBButton.text = "Turn On Enemy Healthbars Test";
HBButton.text = "Turn Off Enemy Healthbars Test";
Answer by Ran-Quan
Mar 21 at 06:07 AM
PlayerPrefs keys are case-sensitive, so PlayerPrefs.GetInt("HealthBars") will always return 0 since you are setting "Healthbars" instead of "HealthBars".
thank you!!! lol i knew it was a tired error i wasn't seeing :)
Up to 2 attachments (including images) can be used with a maximum of 524.3 kB each and 1.0 MB total.
The best place to ask and answer questions about development with Unity.
To help users navigate the site we have posted a site navigation guide.
If you are a new user to Unity Answers, check out our FAQ for more information.
Make sure to check out our Knowledge Base for commonly asked Unity questions.
If you are a moderator, see our Moderator Guidelines page.
We are making improvements to UA, see the list of changes.
Answers and Comments
110 People are following this question.
Dynamically generate buttons from a single text component
I need to resize my text to button to be visible using Unity 4.6 UI
How To Change Color Of Text On UI When It's Selected | Unity 4.6
Canvas Button persistence
UI Scaling with Button Text