Monday, 16 January 2017



        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;
}


}



  •   Make A Empty Object In Hierarchy Menu And Rename it Progress Bar And Then Drag This Image   On This Empty Object




  •  Import Two Images With Different Colors In Unity




  •   Drag The Image 1 In Empty_Image_Variable And Image 2 In     Full_Image_Variable
  •   Then Click On Play    

              

 Note: You Can Change Bar Size And Position Through Inspector Menu....

                                         


               VIDEO TUTORIAL:   Click Here To Watch 



No comments:

Post a Comment