var buttonTexture : Texture2D;
private var str : String;
private var str1 : String;
private var frameTime : int;
function Start(){
str = "click button";}
function OnGUI()
{
GUI.Label(Rect(10, 10, Screen.width, 30), str);
GUI.Label(Rect(160, 10, Screen.width, 30), str1);
if(GUI.Button(Rect(10,30,buttonTexture.width,buttonTexture.height),buttonTexture)){
str1 = "you clicked me";
str = "you clicked me";
}
GUI.color = Color.green;
GUI.backgroundColor = Color.red;
if (GUI.Button(Rect(10,120,120,30),"word button")){
str1 = "you clicked words button";
}
GUI.color = Color.yellow;
GUI.backgroundColor = Color.white;
if (GUI.RepeatButton(Rect(10,160,100,30),"click center")){
//按住BUTTON 累加次数
frameTime++;
str1= "time"+ frameTime;
}
}
private var str : String;
private var str1 : String;
private var frameTime : int;
function Start(){
str = "click button";}
function OnGUI()
{
GUI.Label(Rect(10, 10, Screen.width, 30), str);
GUI.Label(Rect(160, 10, Screen.width, 30), str1);
if(GUI.Button(Rect(10,30,buttonTexture.width,buttonTexture.height),buttonTexture)){
str1 = "you clicked me";
str = "you clicked me";
}
GUI.color = Color.green;
GUI.backgroundColor = Color.red;
if (GUI.Button(Rect(10,120,120,30),"word button")){
str1 = "you clicked words button";
}
GUI.color = Color.yellow;
GUI.backgroundColor = Color.white;
if (GUI.RepeatButton(Rect(10,160,100,30),"click center")){
//按住BUTTON 累加次数
frameTime++;
str1= "time"+ frameTime;
}
}
本文提供了一个使用Unity GUI系统的示例代码,展示了如何通过GUI系统显示文本、按钮等元素,并实现按钮点击事件的功能。代码中还包含了计数器功能,可以通过长按按钮来增加计数值。
984

被折叠的 条评论
为什么被折叠?



