Created
December 23, 2014 07:01
-
-
Save kankikuchi/20d3c31b87d11a6ebb2e to your computer and use it in GitHub Desktop.
2Dエフェクトのレイヤーを設定【Unity2D】
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 UnityEngine; | |
using System.Collections; | |
public class EffectLayerSetter : MonoBehaviour | |
{ | |
//エフェクト用のレイヤー名 | |
private string EFFECT_SORTING_LAYER_NAME = "Effect"; | |
private void Awake () | |
{ | |
SetSortingLayer (transform); | |
} | |
private void SetSortingLayer (Transform parent) | |
{ | |
//レンダラーがある場合のみレイヤーを設定 | |
if (parent.gameObject.renderer) { | |
parent.gameObject.renderer.sortingLayerName = EFFECT_SORTING_LAYER_NAME; | |
} | |
//子がいる場合には、それにも同じ処理を行う | |
foreach (Transform child in parent.transform) { | |
SetSortingLayer (child); | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment