ArgumentException:无法在Unity C中转换参数#

时间:2018-02-07 02:43:11

标签: c# unity3d

所以我想改变材料的颜色。这是我使用的代码:

public GameObject result;
Color color;
GameObject actualChangingObject;

public void OneOfTheGemsButton(GameObject objectThatChangesColor)
{
    changeColorMenu.SetActive(true);
    gemsMenu.SetActive(false);

    actualChangingObject = objectThatChangesColor;
}

public void OkButton()
{
    color = result.GetComponent<Image>().color;
    actualChangingObject.GetComponent<Material>().color = color;
    actualChangingObject = null;

    changeColorMenu.SetActive(false);
    gemsMenu.SetActive(true);
}

“result”是一个UI图像,其中包含我想要的颜色 所以通过调试我发现这个:color = result.GetComponent<Image>().color;代码行不起作用。有什么想法吗?

1 个答案:

答案 0 :(得分:0)

我只是说:
Color color = new Color(); 代替 Color color;