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
5 days ago
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.
Null reference when I already assign a value? (UI Button and Text)
Clicking a button will display that buttons text in a seperate text-field
[4.6 - UI] Change text on button click via script
Destory button on click and other problem
Find GUI Button and Assign Text