Created
June 18, 2019 16:39
-
-
Save Ratstail91/4f0e3cc21245f7eafea9ce1989e24464 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
//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