Created
November 14, 2018 07:46
-
-
Save HassakuTb/4131fb97f2029d5d0c3f82348a7fbe4c to your computer and use it in GitHub Desktop.
This file contains hidden or 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
| using System.Collections; | |
| using UnityEngine; | |
| [RequireComponent(typeof(CanvasGroup))] | |
| public class FadeOutScreen : MonoBehaviour{ | |
| [SerializeField] private float fadeTime = 0.2f; | |
| [SerializeField] private AnimationCurve alphaCurve; | |
| private CanvasGroup fadeGroup; | |
| private void Start() | |
| { | |
| fadeGroup = GetComponent<CanvasGroup>(); | |
| } | |
| public IEnumerator FadeOut() | |
| { | |
| fadeGroup.blocksRaycasts = true; | |
| float time = 0f; | |
| while(time < fadeTime) | |
| { | |
| fadeGroup.alpha = alphaCurve.Evaluate(time / fadeTime); | |
| time += Time.deltaTime; | |
| yield return null; | |
| } | |
| fadeGroup.alpha = alphaCurve.Evaluate(1f); | |
| } | |
| public IEnumerator FadeIn() | |
| { | |
| float time = fadeTime; | |
| while (time > 0f) | |
| { | |
| fadeGroup.alpha = alphaCurve.Evaluate(time / fadeTime); | |
| time -= Time.deltaTime; | |
| yield return null; | |
| } | |
| fadeGroup.alpha = alphaCurve.Evaluate(0f); | |
| fadeGroup.blocksRaycasts = false; | |
| } | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment