GUI
usingUnityEngine;
usingSystem.Collections;
publicclassUserInterface:MonoBehaviour{
private bool toggleBool=true;
publicTexture pic;
private string passWord="";
//按钮网格
private string[ ]buttonGrids=new string[ ]{"button1","button2","button3","button4"};
private intselectedIndex=0;
private float value=0;
//创建GUI
voidOnGUI(){
//GUI.skin=MyGUI Skin;设置皮肤
//自动布局
//开始横向布局
GUILayout.BeginHorizontal();
if(GUILayout.Button("结束")){
print("结束");
}
//两个按钮中间偏移100个像素
GUILayout.Space(100);
GUILayout.Button("开始");
GUILayout.Box("text");
//嵌套一个纵向布局
GUILayout.BeginVertical();
GUILayout.Label("nihao");
value=GUILayout.HorizontalSlider(value,0,10);
GUILayout.EndVertical();
GUILayout.EndHorizontal();
//开始一个现实区域
GUILayout.BeginArea(newRect(50,50,200,100));
//toggleBool=GUILayout.Toggle(toggleBool,pic);
//单选框
toggleBool=GUILayout.Toggle(toggleBool,"同意");
//密码输入框
passWord=GUILayout.PasswordField(passWord,'*');
//按钮网格
selectedIndex=GUILayout.SelectionGrid(selectedIndex,buttonGrids,2);
GUILayout.EndArea();
//自定义布局
if(GUI.Button(newRect(50,200,100,48),"text")){
print("text");
}
float width=120;
float hight=150;
float screenWidth=Screen.width;
float screenHight=Screen.height;
float x=(screenWidth-width)/2;
float y=(screenHight-hight)/2;
GUI.BeginGroup(new Rect(x,y,width,hight));
GUI.Box(new Rect(0,0,width,hight),"LevelSelect");
if(GUI.Button(new Rect(10,30,100,30),"Level1")){
print("loadineLevel1");
}
if(GUI.Button(newRect(10,70,100,30),"Level2")){
print("loadineLevel2");
}
if(GUI.Button(newRect(10,110,100,30),"Level3")){
print("loadineLevel3");
}
GUI.EndGroup();
}
}
UGUI
usingUnityEngine;
usingSystem.Collections;
using UnityEngine.UI;
publicclassUGUIScript:MonoBehaviour{
publicText myText;
public InputField inputField;
voidStart( ){
}
voidUpdate( ){
}
publicvoidButtonPressed( ){
myText.text="登录成功";
}
publicvoidToggleChange(boolisChioce){
print(isChioce);
}
public void InputFieldValueChange(stringstr){
print(str);
if(str.Length>5){
inputField.text=str.Substring(0,5);
}
}
public void InputFieldEditEnd(stringstr){
print(str);
}
}