Textures showing in the wrong order on camera

One object is on top of another. But sometimes the second object is being shown on top of the first.
How can i fix this?

if the problem is in unity 5.2 NGUI, the order in the hierarchy is also the order of drawing the object, the first in the order will be drawn first (and be on the bottem).
you can change the order by rearranging the hierarchy.
or with code using the (rect)transform component.
Unity - Scripting API: Transform.SetSiblingIndex

if you sprite renderers, the order is set by “sorting layer” and “order in layer”

Problem: You problem is caused because both sprites are on the same layer and unity cant decide which one to display first, so its kind of random the order it will show.

Solution: If you click on the object you can modify the Order in Layer from the Sprite Renderer in the inspector.
The higher the number is, the closer it’ll be to the camera.

alt text