카테고리 없음

[Unity] 3D font set layer, order

Kim2558 2018. 12. 2. 14:58


1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
 
 [ExecuteInEditMode]
public sealed class Font : MonoBehaviour
{
 
    [SerializeField]
    private string SortingLayerName = "Default";
 
    [SerializeField]
    private int SortingOrder = 0;
 
    public void OnValidate()
    {
        apply();
    }
 
    public void OnEnable()
    {
        apply();
    }
 
    private void apply()
    {
        var meshRenderer = gameObject.GetComponent<MeshRenderer>();
        meshRenderer.sortingLayerName = SortingLayerName;
        meshRenderer.sortingOrder = SortingOrder;
    }
}
cs