脚本总索引:http://game.ceeger.com/Script/index.Classes.html
1 按钮生成function OnGUI () {
if (GUI.Button (Rect (10,10,150,100), "I am a button")) {
print ("You clicked the button!");
}
}
2 按钮场景载入
/* Example level loader */
function OnGUI () {
// Make a background box
GUI.Box (Rect (10,10,100,90), "Loader Menu");
// Make the first button. If it is pressed, Application.Loadlevel (1) will be executed
if (GUI.Button (Rect (20,40,80,20), "Level 1")) {
Application.LoadLevel (1);
}
// Make the second button.
if (GUI.Button (Rect (20,70,80,20), "Level 2")) {
Application.LoadLevel (2);
}
}
3 按钮点击生效时间
/* Flashing button example */
function OnGUI () {
if (Time.time % 2 < 1) {
if (GUI.Button (Rect (10,10,200,20), "Meet the flashing button")) {
print ("You clicked me!");
}
}
}
4 创建按钮背景BOX
/* Screen.width & Screen.height example */
function OnGUI () {
GUI.Box (Rect (0,0,100,50), "Top-left");
//Rect 生成2D矩形的函数,用于摄像机,画面,GUI
GUI.Box (Rect (Screen.width - 100,0,100,50), "Top-right");
GUI.Box (Rect (0,Screen.height - 50,100,50), "Bottom-right");
GUI.Box (Rect (Screen.width - 100,Screen.height - 50,100,50), "Bottom-left");
}
5 在按钮上显示文字
/* String Content example */
function OnGUI () {
GUI.Label (Rect (0,0,100,50), "This is the text string for a Label Control");
//显示文字
}
6 显示图像,声明一个公共变量的Texture2D,并通过这样的内容作为参数变量的名称
/* Texture2D Content example */
var controlTexture : Texture2D; //controlTexture为图像的名称
function OnGUI () {
GUI.Label (Rect (0,0,100,50), controlTexture);
}
7 显示图像的例子