Author Topic: UISlider bug  (Read 7641 times)

Noi14

  • Jr. Member
  • **
  • Thank You
  • -Given: 10
  • -Receive: 0
  • Posts: 57
    • View Profile
UISlider bug
« on: March 09, 2014, 05:15:59 PM »
This code doesn't work:
  1.         float energy = 0;
  2.  
  3.         void Update () {
  4.                 energy += (1*Time.deltaTime);
  5.  
  6.  
  7.                 GameObject.Find("Control - Simple Progress Bar").GetComponent< UISlider >().value  = (energy/100);
  8.         }
  9.  

To fix it I must use:
  1.         float energy = 0;
  2.  
  3.         void Update () {
  4.                 energy += (1*Time.deltaTime);
  5.  
  6.                 GameObject.Find("Control - Simple Progress Bar").GetComponent< UISlider >().value = (float)(System.Math.Truncate((double)(energy/100)*100.0) / 100.0);
  7.         }
  8.  

Is very easy to reproduce.
I think this should be fixed.

cyx

  • Newbie
  • *
  • Thank You
  • -Given: 0
  • -Receive: 0
  • Posts: 17
    • View Profile
Re: UISlider bug
« Reply #1 on: March 09, 2014, 05:33:56 PM »
how about:

  1.     float energy = 0f;
  2.     UISlider slider;
  3.  
  4.     void Awake() {
  5.         slider = GameObject.Find("Control - Simple Progress Bar").GetComponent< UISlider >();
  6.     }
  7.    
  8.     void Update () {
  9.         energy += Time.deltaTime;
  10.  
  11.         slider.value = energy / 100f;
  12.     }
  13.  

I would suggest to find the object and component only once, if you need it in the update cycle. And 100f should work if you wanna be sure to get a float result.

Noi14

  • Jr. Member
  • **
  • Thank You
  • -Given: 10
  • -Receive: 0
  • Posts: 57
    • View Profile
Re: UISlider bug
« Reply #2 on: March 09, 2014, 06:11:19 PM »
Yes I know it, I posted scipt in that way so as to make easy finding problems.

BeShifty

  • Jr. Member
  • **
  • Thank You
  • -Given: 5
  • -Receive: 7
  • Posts: 52
    • View Profile
Re: UISlider bug
« Reply #3 on: March 09, 2014, 08:27:41 PM »
Could you describe what's happening?

Noi14

  • Jr. Member
  • **
  • Thank You
  • -Given: 10
  • -Receive: 0
  • Posts: 57
    • View Profile
Re: UISlider bug
« Reply #4 on: March 10, 2014, 05:36:08 AM »
UISlider value change without graphic modification.

Noi14

  • Jr. Member
  • **
  • Thank You
  • -Given: 10
  • -Receive: 0
  • Posts: 57
    • View Profile
Re: UISlider bug
« Reply #5 on: March 10, 2014, 05:56:24 AM »

ArenMook

  • Administrator
  • Hero Member
  • *****
  • Thank You
  • -Given: 337
  • -Receive: 1171
  • Posts: 22,128
  • Toronto, Canada
    • View Profile
Re: UISlider bug
« Reply #6 on: March 10, 2014, 07:28:37 PM »
Comment out line 131 in UIProgressBar.cs:
  1. //if (Mathf.Abs(before - this.value) > 0.001f)