Unity UGUI与3D物体之间遮挡响应
常见写法
UGUI Image响应点击
通过实现IPointClickHandler接口去响应点击
private bool index = false;
public void OnPointerClick(PointerEventData eventData)
{
if (index)
GetComponent<Image>().color = Color.white;
else
GetComponent<Image>().color = Color.red;
index = !index;
}
3D物体响应点击
通过OnMouseDown来响应点击
private bool flag = false;
private void OnMouseDown()
{
if (flag)
GetComponent<MeshRenderer>().material.color = Color.white;
else
GetComponent<MeshRenderer>