GUI还可以定义一个窗口,在窗口里面进行控件的添加:
using UnityEngine;
using System.Collections;
public class getbutton : MonoBehaviour {
private Rect windowRect;
void Start () {
windowRect = new Rect(20, 20, 200, 200);
}
// Update is called once per frame
void Update () {
}
void OnGUI()
{
windowRect = GUI.Window(0, windowRect, Mywindowfunc, "我窗口");
}
void Mywindowfunc(int windowId) {
if(GUI.Button(new Rect(10,20,100,20),"开始")){
print("游戏开始........");
}
GUI.DragWindow(new Rect(0, 0, 10000, 1000));
}
}
效果如图;
这里注意,GUI的函数,在Update 方法里面是没有用的,只有在OnGUI函数里面才会有效的