新手求助关于Unity3D5.5.2
答案:1 悬赏:70 手机版
解决时间 2021-02-19 22:17
- 提问者网友:我们很暧昧
- 2021-02-19 10:39
新手求助关于Unity3D5.5.2
最佳答案
- 五星知识达人网友:痴妹与他
- 2021-02-19 12:03
图片按钮的两态变化鼠标左键按下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;
编写两个脚本文件
一个是点击按钮的图片变化(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;
我要举报
如以上回答内容为低俗、色情、不良、暴力、侵权、涉及违法等信息,可以点下面链接进行举报!
点此我要举报以上问答信息
大家都在看
推荐资讯