How to place a sprite above a GUI.DrawTexture

I am creating a unity 2D app that includes a feature where you color an image.

I set up a painting functionality where I draw the textures needed on a plane. Currently everything is working fine when i draw the actual image as texture and paint it. The problem is that when i paint, the colors are covering the black lines of the image. Imagine coloring an white background with black outlines.

I am attempting to place the same image as a sprite on top of the GUI.DrawTexture with no luck. No matter what I do the Drawn texture is always on top of the sprite object.

I need the outlines to be over the painting panel. Any ideas?

You can do this by using two cameras and two layers. You have one camera that renders your gui and set its culling mask to everything except your new layer and set its depth to -1 or something. Then with your second camera remove the gui layer component (and probably audio listener) and set its culling mask to nothing except your new layer and set its depth to 0 and set its clear flags to ‘Depth only’.

Then you put the sprite that you want to render on the new layer you created and it should be rendered only by the new camera, above everything else!

Scribe

EDIT:

You are correct, this doesn’t work with OnGUI sorry about that. To make it work keeping the same setup as you have with the foreground and background cams, attach this script to your background camera and disable your foreground cam

var foregroundCam : Camera;

function OnGUI(){
	// [all your other gui stuff]

	if (Event.current.type == EventType.Repaint){
		foregroundCam.Render();
	}
}

That should work! sorry for my first incorrect answer :o