How to draw a Rectangle behind all gameobject?

HI, it’s my first time post a question in Unity, hope this works.

I want to draw a rectangle on a background, but behind one of my gameobject. I used GUI.Box to do that. but the result wasn’t good. The Guibox covered the object.

I was searching for an answer in google for a long time for, but no luck.

Hope someone could help me on it. Thanks.

3 Answers

3

You cannot use GUI to draw anything behind 3d objects. GUI rendering is always done on top of your 3d view. You need a 3d plane.

You could:
a) use a Unity Editor 3d Plane (GameObject → Create Other → Plane).
b) use a Mesh Filter to create your plane by code. You will also need a Mesh Renderer to be able to see it. Both components can be added using Component → Mesh.
c) use a 3d modeler program (3d max or similar) to create your plane and then import it to Unity.

I prefer b and c because Unity planes use many triangles and that is not needed for a plane. I prefer to create my own 2 triangles plane. But as you seem to be starting with this, go with option a. I guess you will also need to assign a material to that plane. Dragging a texture from your assets folder into the plane will do, and unity will create the Material for you. I can help you further if you ask me.

HI, it’s my first time post a question in Unity, hope this works.

I want to draw a rectangle on a background, but behind one of my gameobject. I used GUI.Box to do that. but the result wasn’t good. The Guibox covered the object.

I was searching for an answer in google for a long time for, but no luck.

Hope someone could help me on it. Thanks.

You can call camera.Render() in your OnGUI() method to draw 3D object(s) over the top of UnityGUI