Tag Archives: 4.6

Unity3D: Progressbar using new UI system

Before Unity 4.6 new UI system came out, to create a progress bar, the typical process involve writing the OnGUI() function as follows:

public Texture2D emptyProgressBar; // Set this in inspector.
public Texture2D fullProgressBar;  // Set this in inspector.

void OnGUI() 
    GUI.DrawTexture(Rect(0, 0, 100, 50), emptyProgressBar);
    GUI.DrawTexture(Rect(0, 0, progress, 50), fullProgressBar); = TextAnchor.MiddleCenter;
    GUI.Label(Rect(0, 0, 100, 50), string.Format("{0:N0}%", 
progress * 100f)); }


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:

Read the rest of this entry »


Posted by on August 6, 2015 in Programming, Unity 3d


Tags: , , , , , , , , , ,

Unity3D 4.6 UI: get the button and handle the click event in code

In the new Unity3D UI in v4.6, it is much easier to design fancy UI right within Unity without tertiary tools such as NGUI.

One question frequently met is: how to get access the UI elements such as text, button object in code? Here is the tip:


Read the rest of this entry »


Posted by on December 12, 2014 in Programming, Unity 3d


Tags: , , , , , , , , ,