ngui点击与场景点击判断
注:NGUI 组件上加上 BoxCollider 并设置区域大小
public void OnMouseDown()
{
if (UICamera.hoveredObject == null) //场景的点击
{
a = GameObject.Find("box");
if (b == false)
{
a.renderer.material.color = Color.red;
b = true;
}
else if (b == true)
{
a.renderer.material.color = Color.yellow;
b = false;
}
}
}
或用射线检测
Ray ray=UICamera.mainCamera.ScreenPointToRay(Input.mousePosition);// 向屏幕发射线
RaycastHit hit;
if(Physics.Raycast(ray,out hit,200))//射线的碰撞检测
{
print("点到NGUI");
}