背部颜色Unity

时间:2016-04-17 12:10:43

标签: c# unity3d

我想在Unity中绘制一个红绿色纹理,但它全部显示为黄色。为什么?请帮忙!

    GameObject ekranprawy = GameObject.Find("ekranprawy");
    MeshRenderer rr = ekranprawy.GetComponent<MeshRenderer>();
    int size = 128;
    Texture2D tex = new Texture2D(size, size, TextureFormat.ARGB32, false);
    for (int y = 0; y < size; ++y)
    {
        for (int x = 0; x < size; ++x)
        { 
            if(y > (size / 2))
                tex.SetPixel(x, y, new Color(255, 0, 0, 255));
            else
                tex.SetPixel(x, y, new Color(0,255, 0, 255));
        }
    }
    tex.Apply(); //You need to Apply so that the new texture is sent to the GPU
    rr.material.mainTexture = tex;

1 个答案:

答案 0 :(得分:0)

确保材质的颜色为白色。使用此:

    rr.material.SetColor("_Color", Color.white);