So every game has some type GUI (graphic user interface). The best way (as I see it) is scripting the GUI.
Very simple, so something easy to start with:
function OnGUI(){
GUI.Box(Rect(10, 10, 90, 90), "Hello!");
}
Rect - Shape the box will be, rectangle.
(10, 10, 80, 90)
10 - How far away it begins from the left of the screen.
10 - How far away it begins from the top of the screen.
80 - Total width of rectangle.
90 - Total height of rectangle.
"Hello!" - Text that shows up in the box.
The OnGUI function is updated every frame, just like the update function. Now as long as the script containing this is attached to a game object in the Hierarchy, the GUI will display (Make sure you don't name the script GUI).
Making a GUI button...
if (GUI.Button (Rect (20,40,80,20), "Menu")) {
Application.LoadLevel (1);
}
var icon : Texture2D;
function OnGUI () {
GUI.Label (Rect (0,0,100,50), icon);
}
var icon : Texture2D;
Very simple, so something easy to start with:
function OnGUI(){
GUI.Box(Rect(10, 10, 90, 90), "Hello!");
}
Rect - Shape the box will be, rectangle.
(10, 10, 80, 90)
10 - How far away it begins from the left of the screen.
10 - How far away it begins from the top of the screen.
80 - Total width of rectangle.
90 - Total height of rectangle.
"Hello!" - Text that shows up in the box.
The OnGUI function is updated every frame, just like the update function. Now as long as the script containing this is attached to a game object in the Hierarchy, the GUI will display (Make sure you don't name the script GUI).
Making a GUI button...
if (GUI.Button (Rect (20,40,80,20), "Menu")) {
Application.LoadLevel (1);
}
Making a GUI Icon:
function OnGUI () {
GUI.Label (Rect (0,0,100,50), icon);
}
Making a GUI have an icon and text:
function OnGUI () {
GUI.Box (Rect (10,10,100,50), GUIContent("This is text", icon));
}
Comments
Post a Comment