- Home /
Question by
Burki_07 · Nov 07, 2014 at 11:47 AM ·
spriterenderersorting layers
How sort mesh renderer and sprite renderer?
I have some 2d sprites , I have sorted them in order in inspector, I also have some let say 3d sphere. No matter what value I put in z-axis, I stays behind the sprites. I want them to be on top of all the sprites. Help required.
Comment
can u post an image.it will be easy to understand your problem.
Answer by smoggach · Nov 07, 2014 at 02:35 PM
public class MeshSortingOrder : MonoBehaviour {
public string layerName;
public int order;
private MeshRenderer rend;
void Awake()
{
rend = GetComponent<MeshRenderer>();
rend.sortingLayerName = layerName;
rend.sortingOrder = order;
}
public void Update()
{
if (rend.sortingLayerName != layerName)
rend.sortingLayerName = layerName;
if (rend.sortingOrder != order)
rend.sortingOrder = order;
}
public void OnValidate()
{
rend = GetComponent<MeshRenderer>();
rend.sortingLayerName = layerName;
rend.sortingOrder = order;
}
}
Your answer
![](https://koobas.hobune.stream/wayback/20220613170936im_/https://answers.unity.com/themes/thub/images/avi.jpg)