// Fades out a sprite, starts with a delay in seconds (optional) and destroy gameobject when finished (optional) public void FadeOutSprite(SpriteRenderer spriteRenderer, float duration, float delay = 0f, bool destroy = false) { StartCoroutine(fadeOutEffect.FadeOut(spriteRenderer, duration, delay)); if (destroy) { StartCoroutine(DestroyGameObject(spriteRenderer.gameObject, (duration + delay))); } }
// Update is called once per frame void Update() { // If the player has just been damaged if (isDamaged) { // set the colour of the damageImage to the flash colour. // damageImage.color = flashColour; Debug.Log("Damaged!"); } // Reset the damaged flag. isDamaged = false; if (isDead) { if (fadeOutEffect.FadeOut() <= 0.01f) { Death(); } } }