- Home /
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?
Answer by Scribe · Aug 19, 2014 at 12:59 PM
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
Thank you for the quick answer, i will try that and let you know.
This is Not working. I tried all you said, but the Drawn Texture is always on top of the sprite. Any other Ideas?
Scribe. You are a genius ! That WOR$$anonymous$$S !!! Background image is UNDER the sprites !!!
Your answer
Follow this Question
Related Questions
Painting on objects at runtime/in editor 1 Answer
[SOLVED] Leave footprints/footsteps behind an enemy 1 Answer
just add different texture to terrain at given terrain x and y 0 Answers
RaycastHit2D hit to texture coordinate 0 Answers
how to split a single texture into multiple textures on separate objects in blender? 0 Answers