I really hope some of you can help me out here.
How can I prevent the loadlevel function to execute before the animation has ended.
My code is here:
usingUnityEngine;
usingSystem.Collections;
public class LoadNewScene :SceneFadeInOut{
boolfinish = false;
stringsceneName;
publicstringbackground = “”;
void OnMouseDown(){
sceneName = this.gameObject.name;
print (sceneName);
GameObject.Find(background).animation.Play(“FadeOutBeforeNew”);
Application.LoadLevel(sceneName);
}
}
use that to check if your animation is playing, if it isn’t playing then load your level.
Thanks.
I tried “isPlaying”, but could’nt make it work.
But instead I used the “Invoke” method and it works. Now the newScene waits 2 seconds before executing.
void On MouseDown(){
sceneName = this.gameObject.name;
GameObject.Find(background).animation.Play (“FadeOutBeforeNew”);
Invoke (“newScene”, 2); // waits 2 seconds before executing the method
}
void new Scene(){
Application.LoadLevel(sceneName);
}
}