Label控件:
文本Label
function OnGUI(){
GUI.Label(Rect(10,10,100,20),"Hello World!");
}
图片Label
var textureToDisplay:Texture2D;
function OnGUI(){
GUI.Label(Rect(10,40,textureToDisplay.width,textureToDisplay.height),textureToDisplay);
}
Box控件:
文本Box
function OnGUI(){
GUI.Box(Rect(0,0,Screen.width*0.5,Screen.height*0.5),"This is a title!");
}
图片Box
var textureToDisplay:Texture2D;
function OnGUI(){
GUI.Box(Rect(10,40,textureToDisplay.width,textureToDisplay.height),textureToDisplay);
}
Button控件:
var btnTexture:Texture;//按钮图片
function OnGUI(){
if(!btnTexture)
{
//如果图片未设置,输出错误提示到控制台
Debug.LogError("Please assign a texture on the inspector");
return;
}
//按下图片按钮
if(GUI.Button(Rect(10,10,50,50),btnTexture))
{
Debug.Log("Clicked the button with an image");
}
//按下文字按钮
if(GUI.Button(Rect(10,70,50,30),"Click"))
{
Debug.Log("Clicked the button with text");
}
}
RepeatButton控件:
Repeat Button会在鼠标左键按下期间一直返回true
var btnTexture:Texture;//按钮图片
function OnGUI(){
if(!btnTexture)
{
//如果图片未设置,那么显示提示
Debug.LogError("Please assign a texture on the inspector");
return;
}
//按下图片按钮
if(GUI.
RepeatButton(Rect(10,10,50,50),btnTexture))
{
Debug.Log("Clicked the button with an image");
}
//按下文字按钮
if(GUI.
RepeatButton(Rect(10,70,50,30),"Click"))
{
Debug.Log("Clicked the button with text");
}
}