Hiya! I’m somewhat new to coding and I recently just figured out how to make a fade in effect on my Canvas Group thingy and now I’ve been doing trial and errors for almost an hour now and I can’t figure out how to fade it out after a seconds.
This is the fade in code I made:
using UnityEngine;
using System.Collections;
public class CanvasFadeInAndOut : MonoBehaviour {
CanvasGroup csGrp;
void Awake(){
csGrp = GetComponent<CanvasGroup>();
}
void Start (){
StartCoroutine("FadeIn");
}
IEnumerator FadeIn(){
csGrp.alpha = 0;
float time = 5f;
while(csGrp.alpha < 1){
csGrp.alpha += Time.deltaTime / time;
yield return null;
}
}
}
What do I have to add to have a fade out effect after a few seconds of fading in?