Filling a non-GUI rectangle with a gradient color?

Hi, I’m new to Unity. What’s the best practice to fill a rectangle in a solid color and also, for kicks, whats the best way to fill it with a gradient, smoothly from say, blue going to to red, from top to bottom…

Oh, and don’t want it to be a GUI rect, because it needs to go partially behind other game objects (part of the scene), and I think GUI is always drawn last on top, right?

i.e. something like this:

void FillRectWithGradient(position , size , ColorA, ColorB);

how would I do that? Thanks for any tips!

  1. make a texture to fill (e.g. with 1 pixel)

  2. call GUI.Box or GUI.DrawTexture in OnGUI function and pass your texture as parameter.

  3. for gradient fill - make “one-line” texture (e.g. 1 x 16 pixels) with color gradient, and use it the same way.

I found a solution for this and you can see it here: