Hi,
I am trying to draw a label with a texture2d that I am suppose to color according to user input. But it crashes every time after a few seconds…
This is the code:
//--------------------------------------------------
color = RGBLabelSlider(new Rect(10, 10, 200, 30), color);
texture = new Texture2D(100, 100);
renderer.material.mainTexture = texture;
for (int i = 0; i < 100; i++)
for (int j = 0; j < 100; j++)
texture.SetPixel(i, j, color);
GUI.Label(new Rect(1000, 550, 100, 100), new GUIContent(texture));
texture.Apply();
//--------------------------------------------------
Where RGBLabelSlider() is the function described in CompoundControls tutorial in the Unity Scripting Guide.
This piece of code is inside OnGUI(), in a script that’s attached to the main camera. Also, the main camera has a mesh renderer (or else this line: “renderer.material.mainTexture = texture;” would fail).
color and texture are private members of this script.
This code is crashing unity altogether, so I don’t have access to the console for debugging.
Does anyone have any ideea why this happens?