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");
}
}
}
以上是具体实现代码
具体实现方法:
通过射线判断确定点击的是哪一部分