• Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
  • Asset Store
  • Get Unity

UNITY ACCOUNT

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account
  • Blog
  • Forums
  • Answers
  • Evangelists
  • User Groups
  • Beta Program
  • Advisory Panel

Navigation

  • Home
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
    • Blog
    • Forums
    • Answers
    • Evangelists
    • User Groups
    • Beta Program
    • Advisory Panel

Unity account

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account

Language

  • Chinese
  • Spanish
  • Japanese
  • Korean
  • Portuguese
  • Ask a question
  • Spaces
    • Default
    • Help Room
    • META
    • Moderators
    • Topics
    • Questions
    • Users
    • Badges
  • Home /
avatar image
0
Question by laurienvictoria · Jun 23, 2016 at 11:51 AM · c#asyncloadlevelasyncload level

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

Comment
Add comment
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users

0 Replies

· Add your reply
  • Sort: 

Your answer

Hint: You can notify a user about this post by typing @username

Up to 2 attachments (including images) can be used with a maximum of 524.3 kB each and 1.0 MB total.

Welcome to Unity Answers

The best place to ask and answer questions about development with Unity.

To help users navigate the site we have posted a site navigation guide.

If you are a new user to Unity Answers, check out our FAQ for more information.

Make sure to check out our Knowledge Base for commonly asked Unity questions.

If you are a moderator, see our Moderator Guidelines page.

We are making improvements to UA, see the list of changes.



Follow this Question

Answers Answers and Comments

159 People are following this question.

avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image

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

Level won't load from certain level 1 Answer

  • Anonymous
  • Sign in
  • Create
  • Ask a question
  • Spaces
  • Default
  • Help Room
  • META
  • Moderators
  • Explore
  • Topics
  • Questions
  • Users
  • Badges