If Statement Conditional Not Working

Hi. In my game when the play passes play the ui fade out and it should load the game scene. It should load the game scene when the canvas group’s alpha is at zero. For some reason this does not happen. Here is my code:

using UnityEngine;
using System.Collections;
using UnityEngine.UI;

public class GoToGameOnPlay : MonoBehaviour
{

		public CanvasGroup canvasGroup = null;
		public float speed = 0.2f;
		public float invokeSpeed = 0.5f;

	public void InvokeRep ()
	{
			
			InvokeRepeating ("AlphaToZero", invokeSpeed, invokeSpeed);
			
		if (canvasGroup.alpha <= 0f) {
			Application.LoadLevel("Game");
			CancelInvoke();
		}
		
	}
	
	public void AlphaToZero ()
	{
		
		canvasGroup.alpha = canvasGroup.alpha - 0.1f; 
		
		
	}

}

Please help. Thanks! :slight_smile:

Call the InvokeRepeating statement when you want to leave the scene. The canvasGroup.alpha check should be in your Update() method because it should check the alpha each frame.