I am trying to change the value of a slider trough a script
This is my first time posting here so I want to apologise in advance if I make any mistakes.
So I created a slider using Unitys already built-in UI. I intended to use this Slider as a sorta stamina bar.
I went ahead and added something to Unitys FirstPersonController script which would then decrease the value of the slider everytime I jumped.
GameObject.Find("Slider").GetComponent<Slider>().value.Equals(GameObject.Find("Slider").GetComponent<Slider>().normalizedValue - 0.2);
So I added this inside the if statement for when my character jumps. But when I start the game and jump I jump but I the value of the slider doesn't decrease.
And I have no clue why since it doesn't give me any error and the code inside the if is executed.
Here is a pastebin of the whole script: http://pastebin.com/5m8E84Zh
I would be very grateful if you could help me.
Answer by _Raphael · Jan 06, 2016 at 06:57 PM
Okay thanks for all the help you would have given me but I dont need it anymore since a friend just showed me what I did wrong.
GameObject.Find("Slider").GetComponent<Slider>().value -= 0.05f;
Essentially I just should not have used .equals because equals compares and then returns a boolean and wanted to set the value.
I am stupid.
Your answer
![](https://koobas.hobune.stream/wayback/20220612055215im_/https://answers.unity.com/themes/thub/images/avi.jpg)