- Home /
Load level async freezing animation for several seconds
Hi - I'm building a game for android. When the screen is swiped on the title screen, I'm using load level async. So whilst the next scene is loading - I move an object across the screen smoothly, and once it's moved to it's final position and the level is loaded, it switches smoothly to the title scene.
The problem I'm having is that the object moves for the first few frames, then freezes for several seconds, and then carries on moving.
I've been googling for a long time, and have tried adding Application.backgroundLoadingPriority = ThreadPriority.Low;
But I can't work out how to make the scrolling smooth?
using UnityEngine;
using System.Collections;
using UnityEngine.UI;
public class AsyncLoad : MonoBehaviour
{
private Vector2 StartPos;
private int SwipeID = -1;
public GameObject overlayTerrain;
public GameObject textMain;
public GameObject buttonAbout;
public GameObject buttonCredits;
Vector3 startPos = new Vector3 (-4.5f, -16f, 237.5f);
Vector3 endPos = new Vector3 (-4.5f, -16f, 267.5f);
public float speed = 1.0F;
private float startTime;
private float journeyLength;
public Transform startMarker;
public Transform endMarker;
public Transform startButton;
public Transform endButton;
public GameObject canvasText;
void Start()
{
textMain.SetActive(true);
buttonAbout.SetActive(true);
buttonCredits.SetActive(true);
startTime = Time.time;
journeyLength = Vector3.Distance(startMarker.position, endMarker.position);
Application.backgroundLoadingPriority = ThreadPriority.Low;
}
void OnSwipeUp()
{
StartCoroutine (LoadMainLevel());
}
public IEnumerator LoadMainLevel()
{
yield return null;
var loadingOperation = Application.LoadLevelAsync(1);
loadingOperation.allowSceneActivation = false;
startTime = Time.time;
float fracJourney = 0;
print ("start "+Time.time );
while(fracJourney<1f)
{
float distCovered = (Time.time - startTime) * speed;
// to travel the whole distance will take 'journeyLength/speed' seconds
fracJourney = distCovered / journeyLength;
print ("fj "+fracJourney + ":"+Time.time);
overlayTerrain.transform.position = Vector3.Lerp(startMarker.position, endMarker.position, fracJourney);
canvasText.transform.position = Vector3.Lerp(startButton.position, endButton.position, fracJourney);
print ("done "+loadingOperation.isDone+ ":"+Time.time);
yield return null;
}
loadingOperation.allowSceneActivation = true;
print ("end"+ ":"+Time.time);
yield return loadingOperation;
}
}
(I've taken out the update so it's quicker to read the relevant parts of the script - in the update it's just checking if the screen has been swiped using touch.input)
Does anyone know if I've missed anything so that I can get the movement of the object to run smoothly?
Best, Laurien
Your answer
Follow this Question
Related Questions
Loading Bar in Different Scenes 1 Answer
Got a problem with Async! 0 Answers
Multiple Cars not working 1 Answer
Distribute terrain in zones 3 Answers