Created
January 22, 2019 02:42
-
-
Save DataGreed/0d903b0f6a5b65f81ce31ea0c2e0d982 to your computer and use it in GitHub Desktop.
Simple script to correct sorting z-sorting for Unity games using both 2d SPrites and 3D-meshes. Adds a property for the mesh that lets you specify its sorting layer
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
using System.Collections; | |
using System.Collections.Generic; | |
using UnityEngine; | |
/// <summary> | |
/// Used to set Sorting Layer for 3D meshes, so they can Z-sort | |
/// correctly when used with 2D Sprites. | |
/// </summary> | |
public class OverrideSortingLayer : MonoBehaviour | |
{ | |
public string sortingLayerName; | |
public int sortingOrder; | |
private Renderer usedRenderer; | |
// Start is called before the first frame update | |
void Start() | |
{ | |
if (!string.IsNullOrEmpty(sortingLayerName)) | |
{ | |
usedRenderer = GetComponent<Renderer>(); | |
usedRenderer.sortingLayerName = sortingLayerName; | |
usedRenderer.sortingOrder = sortingOrder; | |
} | |
} | |
// Update is called once per frame | |
void Update() | |
{ | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment