0
\$\begingroup\$

In Unity, I am building a 2D puzzle game, however I need to make sure that certain sprites are rendered on top of other sprites when they are above them.

Here is an example switch (left) and block (right).

Switch on the left, block on the right.

I wanted to make sure that the green block appears on top of the green switch when it passes over it, so how do I avoid a situation like this happening?

enter image description here

\$\endgroup\$
3
\$\begingroup\$

SpriteRenderer has Order in layer inspector property which determines sprite draw order.

You can see how to use it in this tutorial video: https://unity3d.com/learn/tutorials/modules/beginner/2d/sorting-layers

\$\endgroup\$
  • 1
    \$\begingroup\$ Thanks! That worked perfectly, turned out I was just ordering the layers in the opposite order to the way should have been. \$\endgroup\$ – 3lliot Oct 20 '15 at 11:49
0
\$\begingroup\$

The selected answer does the job. If you want to organize the pieces that a certain kind appear on top of another kind, and you have a lot of pieces, take a look at Sorting Layers. If not, you learnt something new ;)

\$\endgroup\$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.