Join the social network of Tech Nerds, increase skill rank, get work, manage projects...
 
  • Incorporate Progress Bar in Unity3D

    • 0
    • 4
    • 1
    • 1
    • 1
    • 0
    • 0
    • 0
    • 1.22k
    Comment on it

    How to make a progress bar in Unity3D Game

    Calling LoadLevelAsync like TheDarkVoid suggested will start the loading process. You could put it in a coroutine so other parts of the game can keep running. It returns an AsyncOperation.

    Example:

    1. var small:GUISkin;
    2. private var loadingArea:Rect;
    3. private var barDisplay : float = 0;
    4. private var pos:Rect;
    5. private var size : Vector2;
    6.  
    7. var emptyProgressBar : Texture2D;
    8. var fullProgressBar : Texture2D;
    9. var progress : Texture2D;
    10. var simpleskin:GUISkin;
    11.  
    12. function Start()
    13. {
    14. loadingArea = Rect(0,0,Screen.width,Screen.height);
    15. skin = small;
    16. txtPos = Rect(380,180,273,81);
    17. pos = Rect((Screen.width/2)-200,270,520,65);
    18. size = Vector2(400,75);
    19. StartCoroutine(LoadALevel(levelName));
    20. }
    21.  
    22. public IEnumerator LoadALevel(string levelName)
    23. {
    24. async = Application.LoadLevelAsync(levelName);
    25. yield return async;
    26. }
    27.  
    28. void OnGUI()
    29. {
    30. if (async != null)
    31. {
    32. barDisplay = float.Parse(async.progress.ToString());
    33. GUI.BeginGroup (loadingArea);
    34. GUI.skin = skin;
    35. GUI.Box(loadingArea,"");
    36. GUI.Label(txtPos,text);
    37. GUI.EndGroup();
    38. GUI.BeginGroup (pos);
    39. GUI.skin = simpleskin;
    40. GUI.Box (new Rect (0,0, size.x, size.y),emptyProgressBar);
    41. GUI.BeginGroup (new Rect (0, 0, size.x * barDisplay, size.y));
    42. GUI.Box (new Rect (0,0, size.x, size.y),fullProgressBar);
    43. GUI.EndGroup ();
    44. GUI.EndGroup ();
    45. }
    46. }

    The above example will help you create a progress bar that will show progress of loading the desired scene.

    Happy Coding......

 1 Comment(s)

Sign In
                           OR                           
                           OR                           
Register

Sign up using

                           OR                           
Forgot Password
Reset Password
Fill out the form below and reset your password: