Hi. I have a play button in my game. When the user taps the play button I want all of the UI to fade out. I have a canvas group that controls that alpha of all of these UI elements. Now all I want to do is when the user taps the play button I want all UI elements to fade out and then switch to the game scene. The game scene looks exactly the same except with none of the previous UI. How can I do this?
[SerializeField] private CanvasGroup canvasGroup = null;
[SerializeField] private float speed = 1f;
private bool callOnce = false;
public void LoadNextScene()
{
if(callOnce == false){
StartCoroutine(LoadNextSceneCoroutine());
}
}
private IEnumerator LoadNextSceneCoroutine() {
callOnce = true;
while(canvasGroup.alpha > 0){
canvasGroup.alpha -= Time.deltaTime * speed;
yield return null;
}
Application.LoadLevel("Scene2");
}
Attach that to a game object and then drag it into the onClick section of the button. Choose the LoadNextScene method and I guess that should do it.