您的位置:首页 > 移动开发 > Unity3D

Unity UI检测碰撞

2016-07-11 14:49 399 查看
using UnityEngine;
using System.Collections;
using UnityEngine.EventSystems;

public class Test : MonoBehaviour {

void Update () {

if (Input.GetMouseButtonDown(0))
{
Ray ray = Camera.main.ScreenPointToRay(Input.mousePosition);
RaycastHit hitinfo;
if(Physics.Raycast(ray,out hitinfo))
{
GameObject obt = hitinfo.collider.gameObject;
if(obt.name == "Cube" && EventSystem.current.IsPointerOverGameObject()==false)
{
print("碰到了3D模型");
}
}

if (EventSystem.current.IsPointerOverGameObject())
{
print("射线检测UI成功");
}
else
{
print("没有检测到射线");
}
}

}
}


避免射线穿过UI而对UI层下的游戏对象产生干涉。
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签:  Unity3D