It uses an asyncOperation to calculate the progress and outputs the current progress to Text (could also be used to make progress bars). //Attach this script to a GameObject //Create a Button ( Create UI Button ) and a Text GameObject ( Create UI Text ) and attach them both to the Inspector of your GameObject //In Play Mode, press your. Browse other questions tagged c# user-interface unity3d progress-bar or ask your own question. The Overflow Blog Improve database performance with connection pooling. The Overflow #43: Simulated keyboards. Featured on Meta Responding to the Lavender Letter and commitments moving forward. Let's take a look at some code.Our progress bar is going to take a displayname, size, our min value, max value, and current value.It's also going to generate textures for itself for the bar-empty, and bar-full.Since a progress bar is essentially two boxes, one box holds the other.The outer box is an empty box and the inner box is scaledto represent the current value relative to the size of the outer box.
This short guide will show you how to make the circle animation below. It’s actually quite simple.
First you will need to create an image to use for your animation. If you’re to lazy you can just use the one I made. Save it into the Assets folder of your Unity project.
We are going to make the background image first. Create a new UI Image object (Gameobject > UI > Image) call it “Loading Circle”. On the Image Component set the Source Image the one you created or downloaded and give it a colour you fancy.
Once you have done that you will need to duplicate it (Right Click > Duplicate). Rename the duplicated gameobject to “Progress”, make it a child of the “Loading Circle” gameobject and change its anchor points to stretch on both the X & Y axis. Again change it’s colour to something you want.
On the “Progress” gameobject change the Image Type on the Image Component to “Filled”, set the Fill Amount as 0.1, and ensure Fill Method is “Radial 360”.
All you need to do now is assign the script below to the “Progress” gameobject and you should have a working animation.
The Code
Before Unity 4.6 new UI system came out, to create a progress bar, the typical process involve writing the OnGUI() function as follows:
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;
- 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:
Unity3d Progress Bar
Compile and Run! That is it! Happy coding!