Skip to content

Instantly share code, notes, and snippets.

@Ratstail91
Created June 18, 2019 16:39
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save Ratstail91/4f0e3cc21245f7eafea9ce1989e24464 to your computer and use it in GitHub Desktop.
Save Ratstail91/4f0e3cc21245f7eafea9ce1989e24464 to your computer and use it in GitHub Desktop.
//how to call the hitstun animation
StartCoroutine(TriggerHit(0.8f)); //0.8 seconds of invulnerability
IEnumerator TriggerHit(float delay) {
invulnerable = true; //allow for a window of time to get away
StartCoroutine(TriggerHitGraphic(0.1f, delay - 0.1f));
yield return new WaitForSeconds(delay);
invulnerable = false;
}
IEnumerator TriggerHitGraphic(float redDelay, float opacityDelay) {
//flash red
renderer.color = Color.red; //renderer is a reference to the SpriteRenderer component
yield return new WaitForSeconds(redDelay);
renderer.color = Color.white;
renderer.material.color = new Color(1f, 1f, 1f, 0.75f);
yield return new WaitForSeconds(opacityDelay);
renderer.material.color = Color.white;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment