using System.Collections; using System.Collections.Generic; using UnityEngine; [ExecuteInEditMode] public class ToonOutline : MonoBehaviour { public Color color = Color.black; [Range(0, 3)] public float outlineSize = 1f; private MeshRenderer meshRenderer; private void Awake() { meshRenderer = this.GetComponent<MeshRenderer>(); } private void OnEnable() { updateOutline(true); } private void OnDisable() { updateOutline(false); } void updateOutline(bool outline) { MaterialPropertyBlock mpb = new MaterialPropertyBlock(); meshRenderer.GetPropertyBlock(mpb); float size = 0; if (outline) { size = outlineSize; } else { size = 0; } mpb.SetColor("_OutlineColor", color); mpb.SetFloat("_OutlineSize", size); meshRenderer.SetPropertyBlock(mpb); } }
Preview:
downloadDownload PNG
downloadDownload JPEG
downloadDownload SVG
Tip: You can change the style, width & colours of the snippet with the inspect tool before clicking Download!
Click to optimize width for Twitter