Skip to content

Instantly share code, notes, and snippets.

@HassakuTb
Last active July 20, 2016 18:11
Show Gist options
  • Save HassakuTb/f40cf01579e9651bf220f86932cff5a8 to your computer and use it in GitHub Desktop.
Save HassakuTb/f40cf01579e9651bf220f86932cff5a8 to your computer and use it in GitHub Desktop.
Blink children objects
/**
NYSL Version 0.9982 (en) (Unofficial)
----------------------------------------
A. This software is "Everyone'sWare". It means:
Anybody who has this software can use it as if he/she is
the author.
A-1. Freeware. No fee is required.
A-2. You can freely redistribute this software.
A-3. You can freely modify this software. And the source
may be used in any software with no limitation.
A-4. When you release a modified version to public, you
must publish it with your name.
B. The author is not responsible for any kind of damages or loss
while using or misusing this software, which is distributed
"AS IS". No warranty of any kind is expressed or implied.
You use AT YOUR OWN RISK.
C. Copyrighted to Hassaku
D. Above three clauses are applied both to source and binary
form of this software.
*/
using UnityEngine;
/// <summary>
/// blink renderer
/// </summary>
public class Blinker : MonoBehaviour{
private bool isBlinking { get; set; }
private Renderer[] renderers { get; set; }
public void StartBlink() {
isBlinking = true;
}
public void StopBlink() {
isBlinking = false;
foreach (var renderer in renderers) {
renderer.enabled = true;
}
}
protected void Awake() {
isBlinking = false;
renderers = GetComponentsInChildren<Renderer>();
}
protected void Update() {
if (!isBlinking) return;
foreach (var renderer in renderers) {
renderer.enabled = !renderer.enabled;
}
}
}
@HassakuTb
Copy link
Author

NG Case

  • There is inactive GameObject when Awake method was running.
  • There is unable Renderer when Awake method was running.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment