public void OnClickRay() { Ray ray = new Ray(); RaycastHit shootHit; ray.origin = cameras.transform.position; ray.direction =cubes.transform.position-cameras.transform.position; if(Physics.Raycast(ray,out shootHit)) { string ShitName = shootHit.collider.gameObject.name; if (ShitName == "4GCUbe") { ShowUI(UI.RESULT); ShowChild(Access4G, "4GAccess"); } else if(ShitName== "5GCUbe") { ShowUI(UI.INPUTNAME); ShowChild(Access5G, "5GAccess"); } else if(ShitName== "IndoorCUbe") { ShowUI(UI.FORU); PassiveeDistrbution.SetActive(false); ShowChild(ActiveDistrbution, "Active Distribution"); } else if(ShitName == "SateelliteCUbe") { ShowUI(UI.FOTDS); ShowChild(Satilite, "Satilite"); } } }
通过射线判断点击的是哪一部分
原文:https://www.cnblogs.com/clhxxlcj/p/10916738.html