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資源,運行 后可以通過敲擊空格鍵切換預定的皮膚。