Add an outline to an object
masterYou can add an outline to a Unity GameObject using two methods:
Method 1: Editor (Drag-and-Drop)
Drag and drop the Outline.cs script directly onto the target GameObject in the Unity Editor. The required outline materials will be loaded automatically at runtime.
Method 2: Programmatic (C#)
Add the Outline component via script and configure its properties. To toggle the outline visibility, use the enabled property rather than adding or removing the component to ensure optimal performance.
var outline = gameObject.AddComponent<Outline>();
outline.OutlineMode = Outline.Mode.OutlineAll;
outline.OutlineColor = Color.yellow;
outline.OutlineWidth = 5f;
// To toggle visibility, use enabled:
outline.enabled = true;