【Unity笔记】经典的鼠标点击射线检测碰撞
时间:2017-07-18 00:55:31
收藏:0
阅读:482
void Update (){ if(Input.GetMouseButton(0)){ //从摄像机发出到点击坐标的射线 Ray ray = Camera.main.ScreenPointToRay(Input.mousePosition); RaycastHit hitInfo; if(Physics.Raycast(ray,out hitInfo)){ //划出射线,只有在scene视图中才能看到 Debug.DrawLine(ray.origin,hitInfo.point); GameObject gameObj = hitInfo.collider.gameObject; Debug.Log("click object name is " + gameObj.name); //当射线碰撞目标为boot类型的物品,执行拾取操作 if(gameObj.tag == "boot"){ Debug.Log("pickup!"); } } } }
原文:http://www.cnblogs.com/guxin/p/unity-mouse-click-raycast-detect-collision.html
评论(0)