Unity3D: How to change Transform's (GameObject

2019-09-05 07:11发布

In old versions of Unity Component's renderer had material, now UnityEngine.Renderer has material, but Component.renderer doesn't have. How can I change the color of my object?

private Transform myTransform;

...

private void changeColor()
{
    myTransform.renderer.**material**.color = Color.red;
    // renderer doesn't have *material*
}

1条回答
Emotional °昔
2楼-- · 2019-09-05 07:42

By this thread, try

GetComponent<Renderer>().material.color = Color.black;
查看更多
登录 后发表回答