if (Physics.Raycast(ray, out hit))
{
if (hit.collider.name.StartsWith("Image"))
{//can not get image
Debug.Log("OK");
image = GameObject.Find(hit.collider.name).gameObject;
Debug.Log ("image.name:"+image.name);
}
}
获取冲突的代码。
如果光线到了图像,我就无法得到碰撞事件。
如何获取图像冲突
如果图像是UI图像。可以使用事件系统的光线投射。或者,如果你所说的图像是指一个2D对象,上面有精灵渲染器。你需要有一个盒子碰撞器。
顺便说一句,image = GameObject.Find(hit.collider.name).gameObject;
是错误的。你可以得到这样的gameObject:image = hit.collider.gameObject;