Skip to content

Instantly share code, notes, and snippets.

@tsubaki tsubaki/AddMaterial.cs
Last active Aug 29, 2015

Embed
What would you like to do?
単一のマテリアルを追加・削除する。
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
You can’t perform that action at this time.