Tasharen Entertainment Forum

Support => NGUI 3 Support => Topic started by: DocLogic on March 16, 2014, 04:39:55 PM

Title: Progress bar not reflecting value
Post by: DocLogic on March 16, 2014, 04:39:55 PM
My progress bar isn't reflecting the actual Value. If I move around the value slider in the editor manually, my progress bar on screen reflects the value perfectly.

My script will change the Value, however the progress bar on screen does not change. If I add Steps to the progress bar, it will work perfectly. However, setting Steps to zero, and the progress bar will only update maybe every 5 seconds.

What am I missing here?

  1. function Start (){
  2.           coolTime -= Time.deltaTime;
  3.       percent = coolTime/coolTimeMax;
  4.       slider.value = percent;
  5.       }
  6.      
  7.  
  8. function Update () {
  9.  
  10.   if (Input.GetAxis("Horizontal") != 0 || Input.GetAxis("Vertical") != 0 )
  11.    {
  12.           coolTime -= Time.deltaTime*2;
  13.       percent = coolTime/coolTimeMax;
  14.       slider.value = percent;
  15.    }
  16.    if (Input.GetButton("Fire1")){
  17.  
  18.          coolTime -= Time.deltaTime*4;
  19.       percent = coolTime/coolTimeMax;
  20.       slider.value = percent;
  21.    }
  22.    
  23. if (coolTime < 0) {
  24.          
  25.           computerObject.SetActive(false);
  26.           computerOFFObject.SetActive(true);
  27.           fuseboxObject.SetActive(true);
  28.           fuseboxOFFObject.SetActive(false);
  29.           ALLCAMERASObject.SetActive(false);
  30.           ALLLIGHTSObject.SetActive(false);
  31.           BATTERYOFFObject.SetActive(false);
  32.       cameraMain2.enabled = true;
  33.       coolTime = 0;
  34.       percent = coolTime/coolTimeMax;
  35.       slider.value = percent;
  36.      
  37.      
  38.    }
  39.    if (coolTime > 100) {
  40.       coolTime = 100;
  41.       percent = coolTime/coolTimeMax;
  42.       slider.value = percent;
  43.    }
  44.    if (BATTERYOFFObject.activeInHierarchy){
  45.       coolTime = 100;
  46.       percent = coolTime/coolTimeMax;
  47.       slider.value = percent;
  48.        BATTERYOFFObject.SetActive(false);
  49.    }
  50.    }
  51.    
  52.    function OnTriggerStay (other : Collider) {
  53.     if (other.gameObject.tag == "Player") {
  54.           coolTime += Time.deltaTime*3;
  55.       percent = coolTime/coolTimeMax;
  56.       slider.value = percent;
  57. }
  58. }
  59.  
Title: Re: Progress bar not reflecting value
Post by: ArenMook on March 17, 2014, 01:30:21 AM
Please update NGUI to 3.5.4.
Title: Re: Progress bar not reflecting value
Post by: DocLogic on March 17, 2014, 09:02:50 AM
This is with 3.5.4...started a new project yesterday with updated NGUI specifically to test.
Title: Re: Progress bar not reflecting value
Post by: hazzy on March 17, 2014, 11:15:52 AM
UIProgressBar.cs > line 115 (public float value) > in the setter, try changing the float value in
if (Mathf.Abs(before - this.value) > 0.001f)
to a value that's lower, like 0.0001f

I'm not sure how this will affect other NGUI components or even if it's a good fix, but it fixed my jerky slider issue.

Basically this happens when the change in value is too small to warrant an update. The slider waits until the delta is big enough and then jerks to the new position.
Title: Re: Progress bar not reflecting value
Post by: DocLogic on March 17, 2014, 11:36:38 AM
That worked!

thank you so much
Title: Re: Progress bar not reflecting value
Post by: ArenMook on March 17, 2014, 07:03:36 PM
That is already fixed in 3.5.4. There is no > check there anymore. It's an inequality check instead:
  1. if (before != this.value)
If you still have a > check then it's not 3.5.4.