Last active
August 29, 2015 14:06
-
-
Save tsubaki/ebfd0083762319713a10 to your computer and use it in GitHub Desktop.
単一のマテリアルを追加・削除する。
This file contains 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 AddMaterial : MonoBehaviour { | |
[SerializeField] | |
Material edge; | |
void OnEnable() | |
{ | |
var render = GetComponentInChildren<Renderer>(); | |
int length = render.materials.Length; | |
var materials = render.materials; | |
System.Array.Resize<Material>( ref materials, length + 1); | |
materials[ length ] = edge; | |
render.materials = materials; | |
} | |
void OnDisable() | |
{ | |
var render = GetComponentInChildren<Renderer>(); | |
int length = render.materials.Length; | |
var materials = render.materials; | |
System.Array.Resize<Material>( ref materials, length - 1); | |
render.materials = materials; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment