- Home /
Animation Lag
I am trying to finish a scenefader which uses animations between scenes. My Gameplay Scene consists of a lot of code and stuff going on (I attached a picture below of the hierarchy so you can get a better idea of what I'm talking about). My scenefader works fine for every other scene, but when I load the gameplay scene it fades in, but then lags (with the black fade screen staying active longer than other scene switches) and does not fadeout (instantly switches to gameplay scene after loading is done). Here's a video of my project showing the issue in action - https://youtu.be/q9_cDFnENi4 - While I am pretty happy with the current setup I am also a perfectionist and want to understand what is causing this issue. Been working on this for two weeks and would really appreciate some help.
Here's some code as well:
SceneFader Code:
using UnityEngine;
using System.Collections;
using UnityEngine.SceneManagement;
public class SceneFader : MonoBehaviour {
public static SceneFader instance;
[SerializeField]
private GameObject fadeCanvas;
[SerializeField]
private Animator fadeAnim;
void Awake(){
//Time.timeScale = 1f;
MakeASingleInstance ();
}
void MakeASingleInstance(){
if (instance != null) {
Destroy (gameObject);
} else {
instance = this;
DontDestroyOnLoad (gameObject);
}
}
IEnumerator FadeInAnimate (string levelName){
fadeCanvas.SetActive (true);
fadeAnim.Play ("FadeIn");
yield return StartCoroutine(MyCoroutine.WaitForRealSecond(0.7f));
SceneManager.LoadScene (levelName);
FadeOut ();
}
IEnumerator FadeOutAnimate(){
fadeAnim.Play ("FadeOut");
yield return StartCoroutine(MyCoroutine.WaitForRealSecond(0.7f));
fadeCanvas.SetActive (false);
}
public void FadeIn(string levelName){
StartCoroutine (FadeInAnimate(levelName));
}
public void FadeOut(){
StartCoroutine (FadeOutAnimate());
}
}
MyCoroutine Code:
using UnityEngine;
using System.Collections;
public static class MyCoroutine {
public static IEnumerator WaitForRealSecond(float time){
float start = Time.realtimeSinceStartup;
while (Time.realtimeSinceStartup < (start + time)) {
yield return null;
}
}
}
SceneManager Code:
using UnityEngine .SceneManagement ;
using UnityEngine .UI;
public class ChangeSceneManager : MonoBehaviour {
//public static bool GameStarted=false;
// Use this for initialization
void Start () {
}
// Update is called once per frame
void Update () {
}
public void MainMenu(){
Time.timeScale = 1.0f;
SceneFader.instance.FadeIn("Title Menu");
}
public void HowToPlay(){
Time.timeScale = 1.0f;
SceneFader.instance.FadeIn ("How To Play Scene");
}
public void Play(){
//Time.timeScale = 0f;
SceneFader.instance.FadeIn ("Gameplay");
}
}
Here's the photo of my hierarchy as well:
[1]: /storage/temp/73962-screen-shot-2016-07-13-at-20349-pm.png
Your video is out of the air =/
Also, it may be a problem in Your computer. Is it powerfull enough? Sometimes the lag is caused by the "weak" hardware and we don't realize.
Your answer
Follow this Question
Related Questions
after click a GUI button from Menu to Game there are two screens 1 Answer
How to change Scenes in VR games 1 Answer
Key/Door to new scene 1 Answer
Setting the position of additive scenes in the hierarchy 1 Answer
Scene Loading Issue. 0 Answers