标签:put void color name raw 碰撞 style update draw
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!"); } } } }
标签:put void color name raw 碰撞 style update draw
原文地址:http://www.cnblogs.com/guxin/p/unity-mouse-click-raycast-detect-collision.html