Catagories
Animation
(1)
Camera
(1)
Camera Script
(2)
GUI
(2)
Lerpz
(1)
Moving Objects
(1)
Platform
(1)
Script
(1)
Sied Scrolling
(1)
Third Person
(1)
Unity
(1)
Thursday, 20 January 2011
Thursday, 13 January 2011
Lesson 13/1/11: Example GUI Script
Example GUI Script:
var icon : Texture2D;
function OnGUI () {
// Make a background box
GUI.Box (Rect (Screen.width/2-150,Screen.height/2-75,300,200), "MAIN MENU");
GUI.Box (Rect (Screen.width/2-120,Screen.height/2-50,35,35), GUIContent(icon));
if (GUI.Button (Rect (Screen.width/2-80,Screen.height/2-50, 200, 35), "START GAME")) {
print ("Game Started");
}
GUI.Box (Rect (Screen.width/2-120,Screen.height/2-10,35,35), GUIContent(icon));
if (GUI.Button (Rect (Screen.width/2-80,Screen.height/2-10, 200, 35), "ACHIEVEMENTS")) {
print ("Achievements Started");
}
GUI.Box (Rect (Screen.width/2-120,Screen.height/2+30,35,35), GUIContent(icon));
if (GUI.Button (Rect (Screen.width/2-80,Screen.height/2+30, 200, 35), "SETTINGS")) {
print ("Settings Started");
}
GUI.Box (Rect (Screen.width/2-120,Screen.height/2+70,35,35), GUIContent(icon));
if (GUI.Button (Rect (Screen.width/2-80,Screen.height/2+70, 200, 35), "CREDITS")) {
print ("Credits Started");
}
}
var icon : Texture2D;
function OnGUI () {
// Make a background box
GUI.Box (Rect (Screen.width/2-150,Screen.height/2-75,300,200), "MAIN MENU");
GUI.Box (Rect (Screen.width/2-120,Screen.height/2-50,35,35), GUIContent(icon));
if (GUI.Button (Rect (Screen.width/2-80,Screen.height/2-50, 200, 35), "START GAME")) {
print ("Game Started");
}
GUI.Box (Rect (Screen.width/2-120,Screen.height/2-10,35,35), GUIContent(icon));
if (GUI.Button (Rect (Screen.width/2-80,Screen.height/2-10, 200, 35), "ACHIEVEMENTS")) {
print ("Achievements Started");
}
GUI.Box (Rect (Screen.width/2-120,Screen.height/2+30,35,35), GUIContent(icon));
if (GUI.Button (Rect (Screen.width/2-80,Screen.height/2+30, 200, 35), "SETTINGS")) {
print ("Settings Started");
}
GUI.Box (Rect (Screen.width/2-120,Screen.height/2+70,35,35), GUIContent(icon));
if (GUI.Button (Rect (Screen.width/2-80,Screen.height/2+70, 200, 35), "CREDITS")) {
print ("Credits Started");
}
}
Unity GUI
Making Controls with UnityGUI
UnityGUI controls make use of a special function called OnGUI(). The OnGUI() function gets called every frame as long as the containing script is enabled - just like the Update() function.
GUI controls themselves are very simple in structure.The script function looks like this...
function OnGUI () { GUI code goes here }
creating a simple button.
function OnGUI () {
// Make the first button. If it is pressed, run event
if (GUI.Button (Rect (20,40,80,20), "Click Me")) {
EVENT GOES HERE
}
}
How the code works...
GUI.Button
adds a button element
Rect (20,40,80,20)
The first two numbers are the x and y coordinates.
The second two are width and height.
"Click Me"
This is the text you want on your button.
*Note the if at the beginning makes it run a script when clicked.
useful GUI Link
http://www.cis.sojo-u.ac.jp/~izumi/Unity_Documentation_jp/
Documentation/Components/gui-Basics.html
Thursday, 6 January 2011
Subscribe to:
Posts (Atom)