private Camera aRCamera; Ray ray; RaycastHit hit; aRCamera = GameObject.Find("RenderCamera").GetComponent<Camera>(); if (Input.GetMouseButtonDown(0)) { startPos = Input.mousePosition; ray = aRCamera.ScreenPointToRay(startPos); Debug.DrawRay(ray.origin, ray.direction, Color.red);//1.射线可视 //if(Physics.Raycast(ray,out hit2,int.MaxValue,1<<LayerMask.NameToLayer("Anim"))&&!EventSystem.current.IsPointerOverGameObject())//2.UI穿透问题,命名空间:using UnityEngine.EventSystems; //if(Physics.Raycast(ray,out hit2,int.MaxValue,1<<LayerMask.NameToLayer("Anim")))//3.选择层 if(Physics.Raycast(ray,out hit)) { if (hit.collider != null) { if (hit.collider.tag == "Mode") { Debug.LogError(hit.point);//4.射线点击获取世界坐标 Debug.LogError(hit.collider.name); currentHitObj = hit.collider.gameObject; } } } }
文章来源: https://blog.csdn.net/Snailsnail_Smails/article/details/89682537