Search Unity

  1. Unity 2018.3 is now released.
    Dismiss Notice
  2. The Unity Pro & Visual Studio Professional Bundle gives you the tools you need to develop faster & collaborate more efficiently. Learn more.
    Dismiss Notice
  3. Want more efficiency in your development work? Sign up to receive weekly tech and creative know-how from Unity experts.
    Dismiss Notice
  4. Build games and experiences that can load instantly and without install. Explore the Project Tiny Preview today!
    Dismiss Notice
  5. Nominations have been announced for this years Unity Awards. Celebrate the wonderful projects made by your peers this year and get voting! Vote here!
    Dismiss Notice
  6. Want to provide direct feedback to the Unity team? Join the Unity Advisory Panel.
    Dismiss Notice
  7. Improve your Unity skills with a certified instructor in a private, interactive classroom. Watch the overview now.
    Dismiss Notice

Lag caused by initializing Ads.

Discussion in 'Scripting' started by Venatal, Jan 19, 2016.

  1. Venatal

    Venatal

    Joined:
    Nov 12, 2015
    Posts:
    134
    When ever I request ads in my game which is in the second scene, upon opening the scene I notice terrible lag for 1-2 seconds.
    What advice do you have for me to prevent this lag.
    I have already tried Initializing it in my main menu scene assuming it would load during the splash screen however this was not the case and still there was noticeable lag.
    I know that you have to download the data before its needed but not sure how to accomplish this using Adtapsy.
     
    Last edited: Jan 19, 2016
  2. blitz8897

    blitz8897

    Joined:
    Sep 23, 2018
    Posts:
    1
    me too
    have you found any solution ?
     
  3. shawndingo

    shawndingo

    Joined:
    Oct 4, 2018
    Posts:
    38
    You've brought a dead thread alive... Should create a new one since this is 2 years old.

    But the simple approach is to pause the game when it loads the ad.. Something like this should work. This is what i use in my unity ads.

    Code (CSharp):
    1.  public void ShowRewardedVideo()
    2.     {
    3.         StartCoroutine(WaitForAd());
    4.         ShowOptions options = new ShowOptions();
    5.         options.resultCallback = HandleShowResult;
    6.  
    7.         Advertisement.Show("rewardedVideo", options);
    8.     }
    9.  
    10.     void HandleShowResult(ShowResult result)
    11.     {
    12.         if (result == ShowResult.Finished)
    13.         {
    14.             Game.current.Gold += 15;
    15.             Gold.text = "" + Game.current.Gold;
    16.             Game.current.adCounter = 1;
    17.          
    18.          
    19.             SaveLoad.SaveGame();
    20.             Debug.Log("Video completed - Offer a reward to the player");
    21.             // Reward your player here.
    22.  
    23.         }
    24.         else if (result == ShowResult.Skipped)
    25.         {
    26.             Debug.LogWarning("Video was skipped - Do NOT reward the player");
    27.  
    28.         }
    29.         else if (result == ShowResult.Failed)
    30.         {
    31.             Debug.LogError("Video failed to show");
    32.  
    33.         }
    34.     }
    35.  
    36.  
    37.     IEnumerator WaitForAd()
    38.     {
    39.         float currentTimeScale = Time.timeScale;
    40.         Time.timeScale = 0f;
    41.         yield return null;
    42.  
    43.         while (Advertisement.isShowing)
    44.             yield return null;
    45.  
    46.         Time.timeScale = currentTimeScale;
    47.     }