using UnityEngine; [ExecuteInEditMode] [RequireComponent (typeof (MeshFilter))] [RequireComponent (typeof (MeshRenderer))] public class MeshCopy : MonoBehaviour { public MeshFilter OriginalMesh; [ColorUsage (false)] public Color Color = Color.white; public float Intensity = 1; MeshFilter meshFilter; Renderer rend; Color oldColor = Color.black; float oldIntensity = -1; MaterialPropertyBlock propBlock; string colorProp = "_Color"; void Update () { CheckReferences (); if (OriginalMesh && OriginalMesh.sharedMesh) meshFilter.sharedMesh = OriginalMesh.sharedMesh; else meshFilter.sharedMesh = null; UpdateColor (); } void CheckReferences () { if (!meshFilter) meshFilter = GetComponent (); if (!rend) rend = GetComponent (); if (propBlock == null) propBlock = new MaterialPropertyBlock (); } void UpdateColor () { if (oldColor != Color || oldIntensity != Intensity) { oldColor = Color; oldIntensity = Intensity; rend.GetPropertyBlock (propBlock); propBlock.SetColor (colorProp, Color * Intensity); rend.SetPropertyBlock (propBlock); } } }