Search Unity

Using Play Games Services and AdMob on android - for free!

Discussion in 'Android' started by MD_Reptile, May 20, 2014.

  1. MD_Reptile

    MD_Reptile

    Joined:
    Jan 19, 2012
    Posts:
    2,664
    Hey guys, I struggled a few days at getting the new AdMob (new as in the admob page had me "update" to the new admob, and caused my project to no longer display ads in the old plugin) integrated into a project that I had Play Games Services working for, so I have decided that for anybody else having this problem, that I will post a general how-to for getting them in your project and cooperating.

    First you are going to need the following unity packages:

    Official Play Games Services Unity - download here:

    https://github.com/playgameservices/play-games-plugin-for-unity

    Nabrozidhs Unity Admob Android - you might consider navigating to the pull request and getting the version that won't call ads from the editor! - download here:

    https://github.com/nabrozidhs/unity_admob_android

    And then you will need to set up your play developer console to include play services with your game (there are guides and tutorials from google covering this topic)

    Now here it gets tricky, you need to import the unity package from the play games plugin (import the whole thing), and then integrate it with your project. You can get some help with this on the github readme, and this means you have to set up leaderboards, achievements, and get those ready to test from your developer console, and then configure your project to send calls to the plugin when you unlock achievements, and set high scores and such. You could take this further but that is as much as I needed in my project.

    And when it is done and your satisfied with how it is working in your project (ideally make a backup at this point), you need to import the admob plugin from nabrozidhs github. IMPORTANT NOTE: BEFORE you select to bring every file into your project, your gonna need to compare the ones your bringing in, with the ones existing already from the play games services. Make sure you do not overwrite the already existing play services stuff, like in your projects plugins folder (you can reimport the play services package to double check which it brings if you need to), where the jar files for its functionality are, because the ones included in nabrozidhs plugin are outdated, and will not work properly! This caused me the longest of headaches haha...

    Now you will need to configure an account on apps.admob.com where you get the required ID's for your ad content to appear in game. You need to make calls from your game to this plugin, at the right time, to display the adverts and hide the adverts, and you might do interstitial ads as well if your game could fit that in.

    Before this will all work you need to make sure your manifest is set up to work with nabrozidhs plugin, which you can see the fairly straightforward instructions to do so on his githubs readme!

    Best of luck, and if your get hung up along the way let me know and maybe I could help clarify better.
     
  2. MD_Reptile

    MD_Reptile

    Joined:
    Jan 19, 2012
    Posts:
    2,664
    FOR THOSE LOST ON HOW TO INTEGRATE PLAY SERVICES WITH YOUR GAME! read on ...

    from a post with gamers1432:

    Ok well. Let us see here, you did the "setup" and entered your info, so you must already have an acct and stuff ready, so that means part of the battle is over lol. Now you need to put this in your script thats going to handle loading and hiding ads. Start at the top of what will be your ad handler script with this:

    Code (CSharp):
    1. using GooglePlayGames;
    2. using UnityEngine.SocialPlatforms;
    and then say in the Start() method do this:

    Code (CSharp):
    1. PlayGamesPlatform.Activate();
    and once thats done, you must authenticate you user (this can take some amount of time on mobile networks - possible over a minute, so start near load time of your game so its ready when game scenes start getting loaded in, or before player can do anything) doing something like this:

    Code (CSharp):
    1. // authenticate user:
    2. Social.localUser.Authenticate((bool success) => {
    3. // handle success or failure
    4. if(success) // the login completed successfully
    5. {
    6. LoggedIntoPlayServices = true; // some bool to let us know later were logged in ok before trying to unlock achievements or send scores to a leaderboard
    7. }
    8. });
    and then even further along the code chain you need to maybe unlock an achievement:

    Code (CSharp):
    1. // unlock achievement (achievement ID "Cfjewijawiu_QA")
    2. Social.ReportProgress("Cfjewijawiu_QA", 100.0f, (bool success) => {
    3. // handle success or failure
    4. if(success) // we have successfully sent our acheivement to the play servers
    5. {
    6. // maybe we should show some info in game to alert the player (besides the toaster pop up from the plugin - which is flakey)
    7. }
    8. });
    or maybe we need to post to a leaderboard:

    Code (CSharp):
    1. // post score 12345 to leaderboard ID "Cfji293fjsie_QA")
    2. Social.ReportScore(12345, "Cfji293fjsie_QA", (bool success) => {
    3. // handle success or failure
    4. if(success)
    5. {
    6. // might do something like...
    7. if(NeverEnteredScoreBefore)
    8. {
    9. GivePlayerCookie(); // some sort of interaction after loading the scores... perhaps show the leader boards themselves?
    10. }
    11. }
    12. });

    and you will see many more examples on the readme's of those plugins!

    Good Luck!
     
    Last edited: Aug 19, 2014
  3. bigjobs

    bigjobs

    Joined:
    Feb 24, 2016
    Posts:
    14
    download plugin from https://github.com/unity-plugins/Unity-Admob
    and then


    Admob.Instance().loadInterstitial();

    Unlike banners, interstitials need to be explicitly shown. At an appropriate stopping point in your app, check that the interstitail is ready before showing it:

    if (Admob.Instance().isInterstitialReady()) {
    Admob.Instance().showInterstitial();
    }