Search Unity

  1. Unity 2019.1 is now released.
    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:
    39
    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.     }