Unity3D GUI图形用户界面系统
1.skin变量
using UnityEngine; using System.Collections; public class Skin : MonoBehaviour { public GUISkin[] gskin;//GUISkin资源引用 public int skin_Index = 0; void Update () { if (Input.GetKeyDown(KeyCode.Space)) { skin_Index++; if (skin_Index >= gskin.Length) { skin_Index = 0; } } } void OnGUI() { GUI.backgroundColor = Color.red;//设置背景颜色 GUI.color = Color.yellow;//设置颜色 GUI.skin = gskin[skin_Index];//设置皮肤 GUI.contentColor = Color.green;//设置文本颜色 if (GUI.Button(new Rect(0,0,Screen.width/10,Screen.height/10),"a button"))//创建按钮 { Debug.Log("button has been pressed");//打印点击信息 } GUI.Label(new Rect(Screen.height/10,Screen.width/10,Screen.height/5, Screen.width /5),"Hellow World"); GUI.Box(new Rect(Screen.height / 5, Screen.width / 10, Screen.height / 5, Screen.width / 5), "a Box"); } }
将该脚本挂载到摄像机上后,为其gskin变量挂载两个或两个以上的GUISkin资源,运行 后可以通过敲击空格键切换预定的皮肤。