Before Unity 4.6 new UI system came out, to create a progress bar, the typical process involve writing the OnGUI() function as follows:
Let's see how can we get this done: to make a 'real' loading progress bar, we need to know the data of loading progress to get it shown on our UI (in here I used a Slider to display the current loading progress). In Unity, we can do: AsyncOperation sceneAO; And assign it in a Coroutine called LoadingSceneRealProgress. Description Makes a progress bar. Value goes from 0 to 1, where 0 means 0% of the bar filled and 1 means the bar is at 100% fully filled Progress bar in an Editor Window. Radial Progress Bar by AdultLink - 5. Shaders & Effects. Customizable radial progress bar shader for Unity3D. Allows you to set arc range, minimum and maximum colors, textures, radius, and a few more things. Create HP Bars, Speedometers, rank progress, etc! To display the load progress as a percentage, just like before, when creating the Progress Bar, take the Async Operation Progress value and convert the value to a float between 0 and 0.9: float progressValue = Mathf.Clamp01(loadingOperation.progress / 0.9f).
This is OK, however not recommended in the new GUI system in Unity 4.6+: you don’t want to mix the GUI with the new and legacy system, right?
Here is the process to create a progress bar using the new UI system:
- Create a new project in Unity3D
- Add a UI Image, name it “Background”, set the sprite to the background image;
- Add another UI Image (or duplicate the above background UI object) , name it “Foreground”, set the sprite to the foreground image;
Unity Progress Bar Example
- Change the foreground UI image’s Image type to “Filled”, Fill Method to “Horizontal”
- Create a C# script, name it “Progress.cs”, attach it to the foreground UI image:
Unity Editor Progress Bar
Compile and Run! That is it! Happy coding!