Skip to content

Instantly share code, notes, and snippets.

@kankikuchi
Created December 23, 2014 07:01
Show Gist options
  • Save kankikuchi/20d3c31b87d11a6ebb2e to your computer and use it in GitHub Desktop.
Save kankikuchi/20d3c31b87d11a6ebb2e to your computer and use it in GitHub Desktop.
2Dエフェクトのレイヤーを設定【Unity2D】
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