I have a simple cube in Unity and want to fill its faces with different colors initialized as variables. However, when I run the program, the cube stays white and doesn’t update its color. Only when I go to its material, select the texture and quickly update the settings of the texture, for example Aniso Level, the cube actually displays the right colors. The anwers to this question include using Material.EnableKeyword() but this doesn’t change anything as well.
public Color top;
public Color bottom;
public Color right;
public Color left;
public Color forward;
public Color backward;
// Start is called before the first frame update
void Start()
{
// Create a 4x4 uv map to match the cube
Texture2D texture = new Texture2D(4, 4);
texture.SetPixel(1, 1, top);
texture.SetPixel(1, 3, bottom);
texture.SetPixel(1, 0, right);
texture.SetPixel(1, 2, left);
texture.SetPixel(2, 2, forward);
texture.SetPixel(0, 2, backward);
texture.filterMode = FilterMode.Point;
// Create new material, set the texture and enable the material
Material material = new Material(Shader.Find("Standard"));
material.SetTexture("_MainTex", texture);
material.EnableKeyword("_NORMALMAP");
material.EnableKeyword("_DETAIL_MULX2");
GetComponent<Renderer>().material = material;
}