c# – Programmatically creating a texture for a material in Unity

Im trying to create a black texture in unity for a material, but its not showing up

    // Create a black texture with a size of 800x600
    dotTexture = new Texture2D(800, 600);
    Color[] colors = dotTexture.GetPixels();
    for (int i = 0; i < colors.Length; i++)
        colors[i] = Color.black;
    dotTexture.SetPixels(colors);
    dotTexture.Apply();

    dotMaterial.mainTexture = dotTexture; // Set the texture to the material

I can see the material and material’s albedo texture. but this texture is not getting applied

What am I doing wrong?

Read more here: Source link