Unity3D GUI学习之GUI窗口的使用

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函数里面才会有效的

posted on 2015-11-06 21:33  手撕高达的村长  阅读(1332)  评论(0编辑  收藏  举报

导航