1
\$\begingroup\$

I have no idea what I'm doing wrong here, but I have Unity Ads set up to play at a random interval when the "play" button is pressed. When that happens, the game freezes for a half second, plays the ad, and then goes back to the previous scene before loading the new one.

It plays out like this Menu Scene > player click play > Menu Scene > Ad plays > Menu Scene > Game Scene

I know why this happens I think, when the Ad is done playing it loads a new level, and that takes a second to do hence the lag. My issue is working around this.

Here's my code

    public void Play()
    {
        random = Random.Range(0, adOdds);

        scene = "Game";

        AdDecider(scene, random);
    }

 void AdDecider(string scene, int random)
    {
        if (random == 1)
        {
            ShowAd();        //shows ad
        }
        else
        {
            SceneManager.LoadScene(scene);
        }
    }

void ShowAd()
    {
        if (Advertisement.IsReady() && PurchaseManager.Instance.AdsOn)
        {
            Advertisement.Show("video", new ShowOptions() { resultCallback = HandleAdResult });
        }
        else
        {
            SceneManager.LoadScene(scene);
        }
    }

    private void HandleAdResult(ShowResult result)
    {
        switch (result)
        {
            case ShowResult.Finished:
                SceneManager.LoadScene("Game");
                break;
            case ShowResult.Failed:
                SceneManager.LoadScene("Game");
                break;
            case ShowResult.Skipped:
                SceneManager.LoadScene("Game");
                break;
          }
      }

Like I said, I'm fairly certain the cause of this is that it takes a second to load the Game scene, but it looks uncanny with the rest of the game. If a player hits "skip ad" and then is back at the menu and a half second later is jolted to the actual game I feel like that'll come off as just a bad UI and lower the quality of my game.

Any suggestions on how to beat this?

\$\endgroup\$
  • 1
    \$\begingroup\$ Ads will pause the game, go to the ad, do what an ad does, then resume the game, which will mean you don't get to load anything in the background. Maybe you could get something done with LoadSceneAsync but I'm not sure. \$\endgroup\$ – John Hamilton Dec 14 '17 at 6:48

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.