I’m trying to draw a single GUI pixel, and be able to change its color. I tried this but I cannot figure out how to change the color. brush is a public Texture.
GUI.DrawTexture(new Rect(100,100,1,1),brush,ScaleMode.StretchToFill,false,0);
I tried changing brush to a Texture2D, then using brush.SetPixel(0,0,Color.red); but the compiler says 'texture is not readable, the texture memory cannot be accessed from scripts.
There’s probably a really simple way to draw a single pixel and set the color. Let me know what that is please.
You could create your own texture and change it’s values, or you could set the texture to readable.
To do the former, just make a new texture:
private Texture2D brush;
private int size = 256;
void Awake()
{
brush = new Texture2D(size, size);
ChangeTheColor(Color.red);
}
void ChangeTheColor(Color c)
{
for (int x = 0; x < size / 2; x++)
for (int y = 0; y < size / 2; y++)
brush.SetPixel(x, y, c);
brush.Apply();
}
void OnGUI()
{
GUILayout.Label(brush);
}
For the latter, browse to your texture import settings, set ‘Texture Type’ to ‘Advanced’, and check ‘Read/Write Enabled’.