Unity3D学习笔记之如何实现单击物体弹出GUI窗口
发表于2017-02-17
有些场景中会因为点击了某个物体弹出新的窗口,那么这个功能在开发中是如何实现的呢?这就需要用到接下来给大家介绍下的实现单击物体弹出GUI窗口方法,一起来看看吧。
1、显示视窗及关闭视窗功能
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 | static var WindowSwitch : boolean = false ; var mySkin : GUISkin; var windowRect = Rect (200, 80, 240, 100); function OnGUI () { if (WindowSwitch == true ) { GUI.skin = mySkin; windowRect = GUI.Window (0, windowRect, WindowContain, "测试视窗" ); } } function WindowContain (windowID : int ) { if (GUI.Button (Rect (70,40,100,20), "关闭视窗" )) { WindowSwitch = false ; } } |
2、单击物体弹出GUI窗口
1 2 3 4 5 6 7 8 9 10 11 12 | function OnMouseEnter () { renderer.material.color = Color.red; } function OnMouseDown () { Func_GUIWindow.WindowSwitch = true ; } function OnMouseExit () { renderer.material.color = Color.white; } |