这个问题在这里已有答案:
Handle touches not started on the UI 1回答
How to detect click/touch events on UI and GameObjects 3个答案
我在Unity中使用物理(Physics.Raycast(ray,out hit))
当我触摸屏幕时,我在碰撞点添加一个球体,
另外,我有一个按钮来移除场景中的最后一个球体,
但我有这个问题(当我触摸该按钮上的屏幕时)同时添加和删除了一个新的球体..如何在我按下按钮时禁用Raycast击中场景?
RaycastHit 对象为您提供了大量有关它的内容的信息 . 您可以使用该信息来决定是否要生成球体 .
RaycastHit
Ray ray = Camera.main.ScreenPointToRay(Input.mousePosition); RaycastHit hit; if (Physics.Raycast(ray, out hit, 100)) { if (hit.transform.name != "myButtonName") { //spawn sphere } else { //remove last sphere } }
1 回答
RaycastHit
对象为您提供了大量有关它的内容的信息 . 您可以使用该信息来决定是否要生成球体 .