I am just trying to teach myself the features of the 2D game engine and I am running into an issue that I thought I had figured out but right now, I am confused. I found several posts that show a way to programmicatlly choose the sorting layer for a MeshRenderer, but the solutions do not seem to be working for me. I am guessing I am doing something wrong but I am hoping someone can point me in the right direction.
I currently have a script that looks like the following:
using UnityEngine;
using System.Collections;
public class SetMeshRendererSortingLayer : MonoBehaviour
{
[SerializeField]
private Renderer renderer;
[SerializeField]
private string sortingLayerName;
[SerializeField]
private int sortingOrder;
public void Start()
{
renderer.sortingLayerName = sortingLayerName;
renderer.sortingOrder = sortingOrder;
}
}
I have these in my sorting layers: Default, Foreground
It appears that if I set the Sorting Layer Name to Foreground it doesn’t seem to do anything. Is there something simple I am missing? This appears to be the answer that others have presented and said this is working fine but I haven’t been able to get it to work. I have a ‘ground’ object that is working correctly with the sorting layer only that object’s renderer is a sprite renderer not a mesh renderer. Any help would be appreciated!
Using Unity 5.4.0f3
Thanks!