- Home /
Question by
vincentamato · Dec 20, 2014 at 07:57 PM ·
gamealphaif-statementsloadlevel
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! :)
Comment
Answer by theLucre · Dec 20, 2014 at 08:08 PM
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.
Your answer
Follow this Question
Related Questions
A node in a childnode? 1 Answer
Loadlevel can't see each other. 2 Answers
stop song and play song 0 Answers
Where to get a dungeon model for free???? 0 Answers
How do you make image links in the Main Menu light up/glow when hovering? 1 Answer