å¾çæé®ç两æååé¼ æ å·¦é®æä¸downå弹起upæ触åçäºä»¶
ç¼å两个èæ¬æ件
ä¸ä¸ªæ¯ç¹å»æé®çå¾çååï¼UI代ç ï¼
1 using UnityEngine;
2 using System.Collections;
3
4 public class MyUIButton : MonoBehaviour
5 {
6 public Texture2D[] btn;
7 public string doUpMethodName;
8 public string doDownMethodName;
9 Rect rc;
10 int index = 0;
11
12 void Update()
13 {
14 if(Input.GetMouseButtonUp(0))
15 {
16 rc = guiTexture.pixelInset;
17 rc.x += transform.position.x * Screen.width;
18 rc.y += transform.position.y * Screen.height;
19 if(rc.Contains(Input.mousePosition))
20 {
21 index = 1;
22 SendMessage(doUpMethodName,index);//æé®å¼¹èµ·æ¶çäºä»¶è§¦å
23 }
24 }
25
26 if(Input.GetMouseButtonDown(0))
27 {
28 rc = guiTexture.pixelInset;
29 rc.x += transform.position.x * Screen.width;
30 rc.y += transform.position.y * Screen.height;
31 if(rc.Contains(Input.mousePosition))
32 {
33 index = 0;
温馨提示:答案为网友推荐,仅供参考