Skip to content

Instantly share code, notes, and snippets.

@n1ckfg
Created November 19, 2018 04:12
Show Gist options
  • Save n1ckfg/a51f2338b840df2846b91f3b0daf5df7 to your computer and use it in GitHub Desktop.
Save n1ckfg/a51f2338b840df2846b91f3b0daf5df7 to your computer and use it in GitHub Desktop.
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class Reveal : MonoBehaviour {
public bool runOnStart = true;
public bool hideOnStart = true;
public float startDelay = 1f;
public float revealDelay = 0.1f;
private List<Renderer> rens = new List<Renderer>();
private int counter = 0;
private void Awake() {
initRenderers();
}
private void Start() {
if (hideOnStart) showAll(false);
if (runOnStart) runReveal();
}
public void runReveal() {
StartCoroutine(runRevealCo(true));
}
private void initRenderers() {
for (int i = 0; i < transform.childCount; i++) {
rens.Add(transform.GetChild(i).GetComponent<Renderer>());
}
}
public void showAll(bool b) {
for (int i = 0; i < rens.Count; i++) {
rens[i].enabled = b;
}
}
private IEnumerator runRevealCo(bool b) {
yield return new WaitForSeconds(startDelay);
for (int i = 0; i < rens.Count; i++) {
rens[i].enabled = b;
yield return new WaitForSeconds(revealDelay);
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment