unity3d实现3D物体上的点击事件

来源:互联网 发布:知乎 新人 西部世界 编辑:程序博客网 时间:2024/05/16 17:21

在update中检测

首先要在摄像机中添加组件Physics Raycaster

public void Update(){if(Input.getMouseButtonUp(0)){Ray ray = Camera.main.ScreenPointToRay(Input.mousePosition);RaycastHit rayhit;if(Physics.Raycast(ray,out rayhit)){debug.log(rayhit.collider.gamaObject.name);}}