
unity获取鼠标下有哪些UI物体
1个回答
展开全部
public GraphicRaycaster m_CanvasUI; public EventSystem eventSystem; private void Update()
{ if (Input.GetMouseButtonDown(0)) {
CheckSecondUI(Input.mousePosition);
}
} /// <summary>
/// 检测是否有第二层UI
/// </summary>
/// <returns></returns>
public void CheckSecondUI(Vector2 pos)
{
List<GameObject> objList = new List<GameObject>();
PointerEventData eventData = new PointerEventData(eventSystem);
eventData.pressPosition = pos;
eventData.position = pos;
List<RaycastResult> list = new List<RaycastResult>();
CanvasUI.Raycast(eventData, list); if (list.Count > 0)
{ for (int i = 0; i < list.Count; i++)
{
Debug.Log(list[i].gameObject.name);
}
} else {
Debug.Log("没有UI");
}
}12345678910111213141516171819202122232425262728293031323334
当鼠标在屏幕上点击时,会打印出鼠标下所有的UI物体的名称
{ if (Input.GetMouseButtonDown(0)) {
CheckSecondUI(Input.mousePosition);
}
} /// <summary>
/// 检测是否有第二层UI
/// </summary>
/// <returns></returns>
public void CheckSecondUI(Vector2 pos)
{
List<GameObject> objList = new List<GameObject>();
PointerEventData eventData = new PointerEventData(eventSystem);
eventData.pressPosition = pos;
eventData.position = pos;
List<RaycastResult> list = new List<RaycastResult>();
CanvasUI.Raycast(eventData, list); if (list.Count > 0)
{ for (int i = 0; i < list.Count; i++)
{
Debug.Log(list[i].gameObject.name);
}
} else {
Debug.Log("没有UI");
}
}12345678910111213141516171819202122232425262728293031323334
当鼠标在屏幕上点击时,会打印出鼠标下所有的UI物体的名称

2023-05-10 广告
您好!建议咨 深圳市微测检测有限公司,已建立起十余个专业实验室,企业通过微测检测就可以获得一站式的测试与认 证解决方案;(EMC、RF、MFi、BQB、QI、USB、安全、锂电池、快充、汽车电子EMC、汽车手机互 联、语音通话质量),认证遇...
点击进入详情页
本回答由微测检测5.10提供
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询