Hello, how can i make Loading bar, for example i want to fill this by green color, slowly in 5-6 seconds, from the left to the right.
How can i do it? I can’t find any good example in unity DOC.
Thanks
Hello, how can i make Loading bar, for example i want to fill this by green color, slowly in 5-6 seconds, from the left to the right.
How can i do it? I can’t find any good example in unity DOC.
Thanks
I write you simple example with comments for old GUI (write on CSharp).
//Create two texture, for example, in Photoshop. First - empty bar, second - full bar(green)
public Texture2D emptyBar = null;
public Texture2D fullBar = null;
public float maxTime = 5.0f; //max time
private float timing = 0.0f; //for timer
private bool isDone = false;
void Start() {
//Initialization time
timing = 0.0f;
isDone = false;
}
void Update() {
//change time every frame
if(!isDone) {
timing = timing + Time.deltaTime;
if (timing >= maxTime) {
isDone = true;
}
}
void OnGUI() {
//Create bar in center screen and size 400x50;
//First, draw empty bar
GUI.DrawTexture(new Rect(Screen.width/2.0f - 200, Screen.height/2.0f - 25, 400, 25), emptyBar, ScaleMode.StretchToFill);
//Create group with full bar
GUI.BeginGroup(new Rect(Screen.width/2.0f - 200, Screen.height/2.0f - 25, 400.0f * timing / maxTime, 25);
//Draw full bar into group
GUI.DrawTexture(new Rect(0, 0, 400, 25), FullBar, ScaleMode.StretchToFill);
GUI.EndGroup();
}
I hope that it will help you.