I know this has come up before and I have tried the solutions I could find, but still no joy.
I am creating GameObjects on the fly from a prefab. All the objects share the same position, but I want to control the rendering order.
public class MasterBehaviour : MonoBehaviour {
private int scaleLevel = 1;
private float scaler = 0.001f;
private Vector3 scaleVector;
private GameObject scale1;
private GameObject scale2;
private GameObject scale3;
// Use this for initialization
void Start () {
scaleVector = new Vector3(scaler, scaler, scaler);
scale1 = Instantiate(Resources.Load("GridPlane", typeof(GameObject))) as GameObject;
scale2 = Instantiate(Resources.Load("GridPlane", typeof(GameObject))) as GameObject;
scale3 = Instantiate(Resources.Load("GridPlane", typeof(GameObject))) as GameObject;
scale1.transform.localScale = new Vector3(0.1f, 0.1f, 0.1f);
scale2.transform.localScale = new Vector3(1.0f, 1.0f, 1.0f);
scale3.transform.localScale = new Vector3(10.0f, 10.0f, 10.0f);
scale1.GetComponent<Renderer>().sortingOrder = 1;
scale2.GetComponent<Renderer>().sortingOrder = 2;
scale3.GetComponent<Renderer>().sortingOrder = 3;
}
}
Things I’ve tried:
Applying different ids/names to the layers.
Applying the same id/name to the layers.
I should also mention that the layers will eventually house 3D content, so I can’t just transform 1 unit in the Z-axis.
Any help much appreciated
UPDATE: I have tried generating each renderer at runtime, and each material, incase they were sharing the same renderer, but so far to no avail.