Skip to content
Permalink
Branch: master
Find file Copy path
Find file Copy path
Fetching contributors…
Cannot retrieve contributors at this time
24 lines (21 sloc) 819 Bytes
using UnityEngine;
public class ColorPropertySetter : MonoBehaviour
{
//The color of the object
public Color MaterialColor;
//The material property block we pass to the GPU
private MaterialPropertyBlock propertyBlock;
// OnValidate is called in the editor after the component is edited
void OnValidate()
{
//create propertyblock only if none exists
if (propertyBlock == null)
propertyBlock = new MaterialPropertyBlock();
//Get a renderer component either of the own gameobject or of a child
Renderer renderer = GetComponentInChildren<Renderer>();
//set the color property
propertyBlock.SetColor("_Color", MaterialColor);
//apply propertyBlock to renderer
renderer.SetPropertyBlock(propertyBlock);
}
}
You can’t perform that action at this time.