Label控件、BOX控件、Button控件、RepeatButton控件

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");
  }
}


  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值