- Home /
Question by
ahmed kamal · Nov 27, 2013 at 09:42 PM ·
2dspriteunity4.3
2d sprite alwayes overlay 3d game object?
in unity 4.3 you can apply the concept of sorting layer to 2d sprite but how i can sort 2d sprite with 3d object???
i tried to change Z position but i always get the sprite drawn above 3d objects .
Comment
Answer by ahmed kamal · Nov 28, 2013 at 03:13 AM
i found the solution you can set sorting layer name and sorting order for any 3d renderer using the following script
using UnityEngine;
using System.Collections;
public class SetSortingLayer : MonoBehaviour {
public string sortingLayerName; // The name of the sorting layer .
public int sortingOrder; //The sorting order
void Start ()
{
// Set the sorting layer and order.
renderer.sortingLayerName = sortingLayerName;
renderer.sortingOrder=sortingOrder;
}
}
this script already exists in unity 2d demo
One more thing to note, if your shader is not a transparent shader, it will always be drawn before the sprites. This is because the transparent shaders queue are always drawn after the opaque.
Your answer
![](https://koobas.hobune.stream/wayback/20220613122947im_/https://answers.unity.com/themes/thub/images/avi.jpg)