Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/csharp/327.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C# 背色统一_C#_Unity3d - Fatal编程技术网

C# 背色统一

C# 背色统一,c#,unity3d,C#,Unity3d,我想在Unity中绘制一个红绿色纹理,但它全部显示为黄色。为什么?请帮忙 GameObject ekranprawy = GameObject.Find("ekranprawy"); MeshRenderer rr = ekranprawy.GetComponent<MeshRenderer>(); int size = 128; Texture2D tex = new Texture2D(size, size, TextureFormat.ARGB3

我想在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;
GameObject ekranprawy=GameObject.Find(“ekranprawy”);
MeshRenderer rr=ekranprawy.GetComponent();
int size=128;
Texture2D tex=新的Texture2D(大小,大小,TextureFormat.ARGB32,false);
对于(int y=0;y(尺寸/2))
tex.SetPixel(x,y,新颜色(255,0,0,255));
其他的
tex.SetPixel(x,y,新颜色(0255,0255));
}
}
tex.Apply()//您需要应用,以便将新纹理发送到GPU
rr.material.mainTexture=tex;

确保材料的颜色为白色。使用以下命令:

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

还可以从编辑器中更改材质的颜色。