編寫兩個腳本文件
壹個是點擊按鈕時的圖片變化(UI代碼)。
1使用UnityEngine
2使用系統。收藏;
三
4公共類MyUIButton : MonoBehaviour
5 {
6 public texture 2d[]BTN;
7公共字符串doUpMethodName
8公共字符串doDownMethodName
9 Rect rc
10 int index = 0;
11
12無效更新()
13 {
14 if(輸入。GetMouseButtonUp(0))
15 {
16 RC = GUI texture . pixelinset;
17 RC . x+= transform . position . x * screen . width;
18 RC . y+= transform . position . y * screen . height;
19 if(rc。包含(Input.mousePosition))
20 {
21指數= 1;
22 SendMessage(doUpMethodName,index);//按鈕彈出時事件觸發
23 }
24 }
25
26 if(輸入。GetMouseButtonDown(0))
27 {
28 RC = GUI texture . pixel inset;
29 RC . x+= transform . position . x * screen . width;
30 RC . y+= transform . position . y * screen . height;
31 if(rc。包含(Input.mousePosition))
32 {
33指數= 0;