Tasharen Entertainment Forum

Support => NGUI 3 Support => Topic started by: Drakuls on March 09, 2014, 12:45:21 PM

Title: Scene loading progress bar
Post by: Drakuls on March 09, 2014, 12:45:21 PM
Hello! 

Im trying to implement loading progress bar in my Unity game.
The progress bar contains UISlider script. And I cant find a way to feed in a value from a script.

Progress bar has a label. The label is in On Value Change marked with method UILabell.SetCurrentPercent (so it changes with progress bar change).

How to change the progress bar from script ? I have my loading script and basicali there is a variable which changes from 0 - 100. (%).
I tried to make public void function and puted there this my variable, but nothing changes when I set this script/function to UIslider -  On Value Change window.
Do I have to make my variable equal with somekind of NGUI property ?
Title: Re: Scene loading progress bar
Post by: vallcrist on March 09, 2014, 01:13:14 PM
You have to use the UIProgressBar.value property.
Title: Re: Scene loading progress bar
Post by: Drakuls on March 10, 2014, 03:14:00 PM
You have to use the UIProgressBar.value property.
Ok I did like that, but no luck. Getting error: NullReferenceException: Object reference not set to an instance of an object (//on this line    loadProgress = UIProgressBar.current.value;)


  1. private float loadProgress = 0;
  2.  
  3.         void OnGUI() {
  4.         GUI.Label (new Rect(500,20,100,30),"menu");    
  5.        
  6.         if (GUI.Button (new Rect (25, 75, 100, 70), "RACE")) {
  7.                 //      Application.LoadLevel(2);
  8.                        
  9.                         StartCoroutine(DisplayLoadingScreen(levelToLoad));
  10.                 }
  11.  
  12. IEnumerator DisplayLoadingScreen(string level) {
  13.                 GalvKamer.SetActive(false);
  14.                 MenuSkr.SetActive(false);
  15.                 UIroots.SetActive(true);
  16.                
  17.                 AsyncOperation async = Application.LoadLevelAsync(level);
  18.                 while (!async.isDone) {
  19.                        
  20.                         //loadProgress = (int)(async.progress*100);
  21.                         loadProgress = async.progress;
  22.                        
  23.                         yield return null;
  24.                 }
  25.         }
  26.        
  27.         // Update is called once per frame
  28.         void Update () {
  29.                 Progress();
  30.         }
  31.  
  32.         public void Progress () {
  33.  
  34.                 loadProgress = UIProgressBar.current.value;
  35.         }
  36.  
  37. }
  38.  

Title: Re: Scene loading progress bar
Post by: hazzy on March 10, 2014, 04:17:49 PM
You have to get a reference to YOUR progress bar in the scene. Then you can then set the .value property of that progress bar.

You're trying to set a value on a static reference to UIProgressBar from UIProgressBar itself, which may or may not be null at that point. Either way, don't do it like that.
Title: Re: Scene loading progress bar
Post by: ArenMook on March 10, 2014, 08:34:17 PM
Anywhere in the code in a script attached to the same game object as the progress bar:
  1. GetComponent<UIProgressBar>().value = 0.5f;
In an OnChange notification callback:
  1. UIProgressBar.current.value = 0.5f;