HORIZONTAL PROGRESS BAR IN UNITY:-
- Create A Folder And Rename it Scripts
- Create C# Script By Right Click On Folder And Rename It Loading_Bar And Then Open It
- And Copy Paste The Code Which Is Given Below And Save It
using UnityEngine;
using System.Collections;
public class Loading_bar : MonoBehaviour {
public float progress=0;
public Vector2 position=new Vector2(20,40);
public Vector2 size=new Vector2(200,20);
public Texture2D progress_empty_Image;
public Texture2D progress_full_Image;
public float run=0.01f;
public float speed=0;
bool check=false;
void OnGUI()
{
GUI.DrawTexture (new Rect (position.x, position.y, size.x, size.y), progress_empty_Image);
GUI.DrawTexture (new Rect (position.x, position.y, size.x*Mathf.Clamp01(progress),size.y), progress_full_Image);
}
// Update is called once per frame
void Update () {
if (check == false)
{
StartCoroutine (delay());
}
}
IEnumerator delay()
{
check = true;
progress = progress + run;
yield return new WaitForSeconds (speed);
check = false;
}
}
using System.Collections;
public class Loading_bar : MonoBehaviour {
public float progress=0;
public Vector2 position=new Vector2(20,40);
public Vector2 size=new Vector2(200,20);
public Texture2D progress_empty_Image;
public Texture2D progress_full_Image;
public float run=0.01f;
public float speed=0;
bool check=false;
void OnGUI()
{
GUI.DrawTexture (new Rect (position.x, position.y, size.x, size.y), progress_empty_Image);
GUI.DrawTexture (new Rect (position.x, position.y, size.x*Mathf.Clamp01(progress),size.y), progress_full_Image);
}
// Update is called once per frame
void Update () {
if (check == false)
{
StartCoroutine (delay());
}
}
IEnumerator delay()
{
check = true;
progress = progress + run;
yield return new WaitForSeconds (speed);
check = false;
}
}
No comments:
Post a Comment