“`
Ray ray;
//重叠检测的方法
//通过射线来判断,初学者一定要确定UI上面有BoxCollider
public void OverlayCheck()
{
Vector3 pos = Input.mousePosition;
//uiCamera这个是NGUI摄像机,(GameMainXL这个是我自己的类 我NGUI定义在这个类里面了,你们可以直接 ray=uiCamera.ScreenPointToRay(pos))
ray=GameMainXL.uiCamera.ScreenPointToRay(pos);
//检索 所有射线碰到的GameObject
RaycastHit[] hits = Physics.RaycastAll(ray, Mathf.Infinity);
if (hits.Length > 1) {
for (int i = 0; i < hits.Length; i++) {
go [i] = hits [i].collider .gameObject;
//输出叠加的个数
print (i);
}
if (go [1].GetComponent ().speed > go [0].GetComponent ().speed) {
print (go [1].GetComponent ().speed);
print (go [0].GetComponent ().speed);
if (go [1].GetComponent ().speed >=speed) {
go[1].transform.localPosition=Vector3.Lerp((new Vector3(GameMainXL.trasLinestatic[line].localPosition.x

本文介绍了一种使用射线检测方法解决NGUI中多个UI重叠时,判断手指点击到哪个UI的问题。通过`ScreenPointToRay`获取射线,并使用`Physics.RaycastAll`检测所有碰撞的GameObject,比较它们组件上的速度属性来决定响应哪个UI。
最低0.47元/天 解锁文章
2285

被折叠的 条评论
为什么被折叠?



