3 using System.Collections.Generic;
12 [AddComponentMenu(
"Liberi/Blinker")]
13 [Script(ScriptRole.View)]
38 public void Blink (
float duration)
41 StartCoroutine(FlashRedAsync(duration));
43 StartCoroutine(BlinkAsync(duration));
54 IEnumerator BlinkAsync (
float duration)
56 if (duration < BlinkInterval)
59 bool blinkState =
false;
61 _blinkTimeLeft = Mathf.Max(_blinkTimeLeft, duration);
64 var blinkables = GetComponentsInChildren<Renderer>()
66 .Concat(ExtraBlinkables.ToArray())
67 .Where(rend => rend.enabled).ToArray();
69 while (_blinkTimeLeft > 0f)
71 foreach (var rend
in blinkables)
75 rend.enabled = blinkState;
78 blinkState = !blinkState;
81 yield
return new WaitForSeconds(BlinkInterval);
84 foreach (var rend
in blinkables)
93 IEnumerator FlashRedAsync (
float duration)
95 if (duration < BlinkInterval)
98 Color blinkColor = Color.white;
100 _blinkTimeLeft = Mathf.Max(_blinkTimeLeft, duration);
102 SpriteRenderer[] blinkables = GetComponentsInChildren<SpriteRenderer>()
103 .Except(Unblinkables.Select(rend => (SpriteRenderer)rend))
104 .Concat(ExtraBlinkables.Select(rend => (SpriteRenderer)rend)).ToArray();
106 Color originalColor = blinkables[0].color;
108 while (_blinkTimeLeft > 0f)
110 foreach (var rend
in blinkables)
114 rend.color = blinkColor;
117 blinkColor = blinkColor == originalColor ? Color.red : originalColor;
120 yield
return new WaitForSeconds(BlinkInterval);
123 foreach (var rend
in blinkables)
128 rend.color = originalColor;
List< SpriteRenderer > ExtraBlinkables
Targeted SpriteRenderers that are not necesarily children, but want to blink with this blinker...
void Blink(float duration)
Blink the object for the given duration.
void StopBlinking()
Stop blinking the object. This resets the visibility of all renderers.
bool FlashRed
Flash SpriteRenderers Color to red instead of disabling renderers.
float BlinkInterval
The interval at which renderer visibility toggles.
Blinks the renderers in an object on and off. Good for damage effects.
Renderer[] Unblinkables
An array of renderers to exclude from the blink effect.