Draw approximately 100 rectangles with each having a different solid color

Hi there,

I am currently working on my first Unity project and after some fiddling around I finally worked out how to correctly display a solid colored rectangle. The approach I am using is as follows:

// inside onGUI()
rect.tx2DFlash.SetPixel(1,1,'SOME_COLOR');
rect.tx2DFlash.Apply();

GUI.DrawTexture(new Rect(rect.X, rect.Y, 40, 40), rect.tx2DFlash)
// inside onGui()

This code is working fine. When i try to use it to create 100 rectangles with each having a different color changing every frame, the code still works. The problem I run into is the amount of drawcalls (about 100) that are being made. On my PC the code is working but on a device I am only getting like 4 fps.

Is there a way to efficiently create simple rectangles with each having a different color changing each frame?

Thanks in advance!

I expect the problem is doing Apply() so many times every frame. Instead of all that, just make a single white texture once, and use GUI.color to change the color.

–Eric

Hi Eric,

Thanks for the quick response!
It works like a charm :slight_smile: