Can't get the sorting layers to work programmatically
Hi - I finished the Angry Birds variant tutorial in Unity 2D and it works perfectly, besides the fact that when the sky is showing, the linerenderers, which I sent their sorting layer and order programmatically, do not work. It's a very similar problem to this. If I push the sky back far enough on the z-axis, it works, but for some reason, this code is not getting me the results I want.
void LineRendererSetup()
{
catapultLineFront.SetPosition(0, catapultLineFront.transform.position);
catapultLineBack.SetPosition(0, catapultLineBack.transform.position);
catapultLineFront.sortingLayerName = "Foreground";
catapultLineBack.sortingLayerName = "Foreground";
catapultLineFront.sortingOrder = 3;
catapultLineBack.sortingOrder = 1;
print(catapultLineFront.sortingLayerID);
}
This will print a value that's a large negative number. I have checked and my "foreground" layer is after the default layer, and the sky is on the default layer with sorting order 0. Any reason why these are still rendering behind the sky? Thanks so much!
Answer by josbys1 · Jan 28, 2017 at 03:03 AM
Got it! Had the material shader set to a default shader. You need it to be a sprite shader to work!