Highlight Plus 2D · Scripting Support (C#)
The HighlightPlus2D namespace provides a 2D-focused highlighting system for sprites and UI elements. Add using HighlightPlus2D; at the top of your scripts.
MonoBehaviour — The main component that controls all highlight effects on 2D sprites. Attach to any GameObject with a SpriteRenderer or Image component.
bool highlighted get/setEnables or disables the highlight effect. Setting this triggers fade animations if fadeInDuration/fadeOutDuration are configured.
bool ignoreWhen true, the object will not be highlighted by automatic systems (HighlightManager2D/HighlightTrigger2D).
float fadeInDurationDuration in seconds for the highlight fade-in animation.
float fadeOutDurationDuration in seconds for the highlight fade-out animation.
bool previewInEditorWhen true, the highlight effect is visible in the Scene view during edit mode.
void SetHighlighted(bool state)Programmatically sets the highlight state. Equivalent to setting the highlighted property.
TargetOptions effectGroupDetermines which renderers are included (Children, OnlyThisObject, RootToChildren, etc.).
LayerMask effectGroupLayerLayer mask filter applied when effectGroup uses layer-based targeting.
Transform targetOptional explicit target transform for the effect.
bool occluderWhen true, this object acts as an occluder for see-through effects on other objects.
bool polygonPackingEnables tight polygon packing for more accurate sprite outlines that follow the sprite shape.
bool preserveMeshPreserves the original mesh shape when computing the highlight mesh.
void SetTarget(Transform transform)Sets a new target transform and re-initializes the effect on the new hierarchy.
int renderingLayerSorting layer used for rendering the highlight effect.
bool alwaysOnTopWhen true, the effect renders on top of all other sprites regardless of sorting order.
float alphaCutOffAlpha cutoff threshold. Pixels with alpha below this value are excluded from the highlight effect.
bool pixelSnapEnables pixel snapping for pixel-art games to prevent sub-pixel rendering artifacts.
bool autoSizeAutomatically calculates the effect size based on the sprite bounds.
Vector2 centerCustom center offset for the effect when autoSize is disabled.
Vector2 scaleCustom scale for the effect when autoSize is disabled.
float aspectRatioAspect ratio override for the effect bounds.
Vector2 pivotPosPivot position offset for the effect.
float zoomScaleScale multiplier applied to the sprite when highlighted, creating a zoom/grow effect.
float outlineOutline intensity. 0 disables the outline, 1 is fully visible.
Color outlineColorOutline color.
float outlineWidthWidth of the outline effect.
QualityLevel outlineQualityQuality of the outline rendering (Low, Medium, High).
bool outlineSmoothEnables anti-aliased smoothing on the outline edges.
bool outlineExclusiveWhen true, only the outline renders without the glow or other effects, creating a clean outline-only look.
float glowOuter glow intensity. 0 disables the glow.
float glowWidthWidth of the outer glow effect.
QualityLevel glowQualityQuality of the glow rendering.
GlowPassData[] glowPassesArray of glow pass configurations with individual offset, width, and color per pass.
float glowAnimationSpeedAnimation speed of the glow pulsing effect.
bool glowSmoothEnables smoothing on the glow edges.
bool glowDitheringApplies dithering to reduce banding artifacts in the glow.
void SetGlowColor(Color color)Sets the glow color for all glow passes at once.
float overlayOverlay intensity. 0 disables the overlay effect.
Color overlayColorColor of the overlay effect.
float overlayAnimationSpeedSpeed of the overlay pulsing animation.
float overlayMinIntensityMinimum intensity during overlay animation cycles.
float overlayBlendingControls the blending strength of the overlay with the underlying sprite.
int overlayRenderQueueCustom render queue value for the overlay material.
float shadowIntensityIntensity of the drop shadow effect. 0 disables shadows.
Color shadowColorColor of the drop shadow.
Vector2 shadowOffsetOffset of the shadow in X and Y directions.
bool shadow3DEnables 3D perspective shadow mode for an isometric/3D look.
bool shadowDitheringApplies dithering to the shadow edge for softer appearance.
SeeThroughMode seeThroughSee-through rendering mode (Never, WhenHighlighted, AlwaysWhenOccluded).
float seeThroughIntensityIntensity of the see-through silhouette.
Color seeThroughTintColorTint color of the see-through silhouette.
float seeThroughTintAlphaAlpha transparency of the see-through tint.
float seeThroughNoiseAmount of noise/scanline effect applied to the see-through silhouette.
void HitFX(Color color, float fadeOutDuration, float initialIntensity = 1f)Triggers a hit flash effect. The color tints the sprite, fading out over fadeOutDuration seconds starting at initialIntensity (0-1).
event OnObjectHighlightStart(GameObject obj, ref bool cancelHighlight)Fired when the object begins highlighting. Set cancelHighlight to true to prevent the highlight.
event OnObjectHighlightEnd(GameObject obj)Fired when the highlight is removed from the object.
void Refresh()Re-initializes the effect. Call after changing the sprite or target hierarchy.
void UpdateMaterialProperties()Updates all internal material properties. Call after changing effect settings via script.
MonoBehaviour — Automatic highlight management for 2D scenes. Add to a scene to enable pointer-based highlighting for all objects with HighlightEffect2D components. Uses 2D raycasting to detect sprites under the cursor.
static instance HighlightManager2D — read-onlySingleton reference to the HighlightManager2D in the scene.
HighlightOnEvent highlightEventControls when highlighting occurs (OnOverAndClick, OnlyOnOver, OnlyOnClick).
float highlightDurationMaximum duration of the highlight in seconds. 0 means unlimited (stays highlighted while hovered).
LayerMask layerMaskLayer mask for 2D raycast detection. Only sprites on these layers can be highlighted.
Camera raycastCameraCamera used for raycasting. Defaults to Camera.main if not set.
RayCastSource raycastSourceInput source for raycasting (MousePosition, ScreenCenter).
event OnObjectHighlightStart(GameObject obj, ref bool cancelHighlight)Fired when the pointer enters a sprite. Set cancelHighlight to true to prevent highlighting.
event OnObjectHighlightEnd(GameObject obj)Fired when the pointer leaves a highlighted sprite.
Returns the active camera used for raycasting.
MonoBehaviour — Per-object trigger component for 2D highlight interaction. Unlike HighlightManager2D (scene-wide), HighlightTrigger2D provides per-sprite control over input detection.
HighlightOnEvent highlightEventControls when highlighting occurs (OnOverAndClick, OnlyOnOver, OnlyOnClick).
float highlightDurationMaximum duration of the highlight in seconds. 0 means unlimited.
TriggerMode triggerModeDetection method for the trigger (Collider2DEvents, Raycast).
Camera raycastCameraCamera used for raycasting. Defaults to Camera.main.
RayCastSource raycastSourceInput source for raycasting (MousePosition, ScreenCenter).
using UnityEngine;
using HighlightPlus2D;
public class SpriteHighlight : MonoBehaviour
{
void Start()
{
HighlightEffect2D effect = gameObject.AddComponent<HighlightEffect2D>();
// Outline
effect.outline = 1f;
effect.outlineColor = Color.cyan;
effect.outlineWidth = 0.8f;
// Outer glow
effect.glow = 1.5f;
effect.glowWidth = 0.6f;
// Overlay
effect.overlay = 0.5f;
effect.overlayColor = Color.yellow;
effect.overlayAnimationSpeed = 2f;
effect.UpdateMaterialProperties();
effect.highlighted = true;
}
}
using UnityEngine;
using HighlightPlus2D;
public class SpriteDamageFlash : MonoBehaviour
{
HighlightEffect2D effect;
void Awake()
{
effect = GetComponent<HighlightEffect2D>();
}
public void TakeDamage()
{
// White flash that fades over 0.3 seconds
effect.HitFX(Color.white, 0.3f, 1f);
}
}
using UnityEngine;
using HighlightPlus2D;
public class SpriteInteraction : MonoBehaviour
{
void Start()
{
HighlightEffect2D effect = GetComponent<HighlightEffect2D>();
effect.OnObjectHighlightStart += OnHighlight;
effect.OnObjectHighlightEnd += OnUnhighlight;
}
void OnHighlight(GameObject obj, ref bool cancel)
{
Debug.Log($"Hovering: {obj.name}");
// Set cancel = true to prevent highlighting
}
void OnUnhighlight(GameObject obj)
{
Debug.Log($"Left: {obj.name}");
}
}
Help us improve this documentation page.