天天看点

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

在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);

}
}           

继续阅读