Complete Guide On Adding AdMob to Unity Game (Tested on Android & iOS)

Video Statistics and Information

Video
Captions Word Cloud
Reddit Comments
Captions
this is a complete guide on adding admob to unity to get you on a road to make those millions from your game we'll cover from the point of adding the plugin to unity all the way through all the configurations and setups that you'll have to do to run your game on android and ios devices if you feel like there's something missing in the guide be sure to write that in the comments and i'll try to update this video to include that information as well i'm going to be starting with an empty project but you can follow along with the project that you're working on so for the first thing in this project let's go to build settings and i'll switch to android because that's the first device that i'm going to be testing now we can google unity admob and go inside here we want to download the plugin and here is the download link for that plugin drop that plugin inside here and let's click import one note about this plugin is the ios resolver it can actually throw errors if you're using unity 20 21.11 or higher if you get the error just restart unity and you'll be fine now get this popup that some of the things were changed so let's actually rebuild it and while it's rebuilding you want to go to google leads mobile unity and if you want to follow along you can download this zip file right here or inside the sample hello world assets scripts this is the google ad mob controller that i'm going to be using so you can actually take a look inside here it's a very good starting point and i'll show that in a little bit the plugin is downloaded and it's ready to go now we can go inside that hello world assets folder and copy these folders into our project it will create another scenes folder scene one because i already have a scene folder so but we can go inside here and open that up now after the plugin was added i got this message right here enable android outer resolution so i'm gonna actually go ahead and disable it because i'm going to run it manually so to do that you can go to assets external dependency manager and right here you can go under android resolver and run resolve gradle is going to download all the packages that are needed for this plugin to work so we can wait for that our resolution succeeded let's click ok but now let's take a look at what we have from this plugin so the first thing for this plugin we have this google mobile ads settings and this is where you want to place the app id from admob for android and ios i'm going to use a test id for android and a test id for ios another important option that we have here is delay app measurement so what this does when you turn it on it delays when admob starts collecting information so this is important if you need to get a consent from your player to allow admob to collect information to display targeted ads when you enable this the admob will only start collecting information after you initialize admob those are all the settings that we have here and the rest of the settings are inside the script that script that i showed so here it is the google ad mob controller you can go to the admob website and go through an instruction here some of the things are outdated but it still will give you a good understanding of what's going on now the implantation that are inside of this documentation is different than what's used in this controller so this controller is actually using unity events and you can connect what you want to do on each of these events the most important event for me is the earned reward event because this is where you actually want to listen if the user actually successfully earned that reward by watching the reward video the other events are here for you if you want to do something more advanced but if you're just starting with admob this is the one event that you need to make sure that you know how to use so currently it's just changing a text value to user earned reward and if we switch to portrait you can see it right here this is where the values can be changing but to make it more noticeable what i'm going to do is add another action here and i will go and connect image and for the game object i will set active to false so if we get successful reward this google admob image should disappear now let's go inside this file because inside this file this is where you'll find the ad ids that you'll need to replace when you'll be ready to publish if you expand any of these regions you can find the add unit ids that are inside here and these are test unit ids so you can actually test your game with these ids after you're done testing and it works just like you want you need to replace these with the add ids from admob dashboard i was editing the video and there's some more things that i want to mention one of the things is how the buttons are connected so right here you can look through and find what actions are taken here so it's actually connected to the google admob controller this one right here and it's a requesting a banner ad so all of these methods are actually exposed and you can trigger them from another game object another thing is if we go back to the c-sharp file at the top there's set ios app pause on background set to true and this is set so the game would actually pause when the ad is displayed that's a default behavior on android also you can set up test device ids here for your iphone or android another thing is the events if you take a look right here we have six events and if we scroll down and look at the banner there are actually four events used for the banner and the same events actually being used for banner ad for interstitial ad and for the reward ad the reward ad has two more events that are added here but just keep that in mind that the four events that we have here the loaded event the fail to load open event and close event are gonna be triggered by the banner ad rewarded at an interstitial ad so if you want to separate the events for each ad type you can add more events here and instead of assign the same event to each of these ad you can assign the specific one and one more thing with this controller it has the fps meter text and status text and it's helpful when you're testing but when you're releasing the app you want to remove that and the easiest way is to just hide the status bar the scripts will still in the background try to modify that if you want to completely remove that you can go inside here and find wherever this is used and just remove those lines now if you want to add admob with visual scripting i'm currently finalizing super units for that purpose and i was hoping to have it done by now but it's taking more time than i initially thought it would be in the lookout for that video but you can use these events right here and connect it to visual scripting and use it like that for now you'll still have to go to the c-sharp script to modify those unit ids but other than that you can do everything from this controller let's run the project in the editor and right here you can see that there is some test smart banners and we can destroy that banner if we want you can request a rewarded ad and right here you can see that ad was loaded then show the rewarded ad wait for the countdown and when we close you can see that we got the reward and also displaying user earned reward now one important thing that you need to know is that two events actually get triggered when you close the reward video so the closed event gets triggered and the earned reward gets triggered and you can see that if i remove the message right there and i'll run it this time so let's request that reward and the ad is loaded and now show reward ad and there is a status ad opened now if i close you can see that we got the reward but now it's displaying and closed just keep in mind that both these events are triggered when you successfully get the reward and in this case close reward event gets triggered first before the earned reward with that we are ready to run it on our device go to build settings and add the open scene to our scene in the build i'm gonna select the device that i'm gonna run it on and let's click build and run it so i'll call it admob test save it and we'll wait for it to build click allow access okay so the apk is starting to be copied over to my device and right here it's launching so we got our test better at the top so that's good let's destroy that test banner and let's request a rewarded video because that's the most important one we need to make sure it works so add was loaded let's show that rewarded video there is the video and the last thing we need to check is if we get the reward or not so let's close out of this reward and we do get the reward successfully because that banner disappeared at the top and right here we have a message says open add not loaded so that is message coming from this one at the bottom that is a new type of ad that was tested in the hello world project and how it looks is if you click request interstitial ad and let's show the interstitial ad close it when you return back to the game you basically get this kind of ad so if that is something that you you want in your game you can actually use that next step is trying it on ios so here i open the project on my mac and i'm running unity 2021.120 here and right here at the bottom you can see that there's our error from ios resolver and if we go to assets and look for external dependency manager we can't find the ios resolver so we can do just restart the project just close it and open it up again now i don't see that error anymore so we can go to assets and go to external dependency manager and now we can see the ios resolver click on the settings and inside the settings we want to enable this link framework aesthetically so let's click on that and click ok now let's go back here once more and in here there is install cocoapods so the admob plugin is using cocoapods to install the frameworks that are needed for admob and if you click install cocoapods the ios resolver found cocoapods so i don't have to install it on my machine but if you don't have it be sure to install it so i'm ready to build and run the game make sure you switch to ios platform and now i can click build i'm going to create a new folder call it ios admob test click create and we'll choose this folder to save our project in the project is building now after the project is built unc is going to try to install the pods and launch the xcode workspace but on my machine actually throws an error so there's something went wrong when it was trying to install the pods if you don't get this error on your machine that means that you're all good and then your xcode project's going to launch but in my case what i have to do is go to the project folder and find the folder where i built my project if you look here we can find the xcode project but we don't have the xcode workspace so all we have to do is run the pod installed manually you can do that by right-clicking and open a new terminal folder and in here we can just run pod install and that's going to check the pod file that is in this folder and install all of the dependencies now that that is done we can go inside of this folder and we can find the xcode workspace so open that instead of the xcode project and right here we see that unc iphone target and also the pods that were installed one last thing that we have to do is assign the application i'm gonna go ahead and do that and we can click run to run it on my iphone device the build process is gonna start running and there we go we have a successful build now the app is launching on the device here's unity we got our banner and at the top so let's go ahead and destroy the banner ad and now let's request the rewarded video show the rewarded video and wait for it to finish close it and then right there add mob image disappeared so we successfully got the reward if you found this guide helpful be sure to click on the like button and i'll see you in the next one
Info
Channel: Smart Penguins
Views: 47,657
Rating: undefined out of 5
Keywords: Tutorials, GameDev, Smart Penguins, unity, unity game dev, indie gamedev, indie game devlog, game devblog, how to make a game, how to, develop games, brackeys, game making, indie game, game developer, video game, beginner, easy, learn, course, game, develop, programming, coding, basic, make a, introduction, visual scripting, making games, getting started, unity bolt, make money, AdMob to Unity, Adding AdMob, Google Ads Unity, Unity admob ios, unity admob andriod
Id: e-q_CPfu0M0
Channel Id: undefined
Length: 13min 18sec (798 seconds)
Published: Sat Sep 11 2021
Related Videos
Note
Please note that this website is currently a work in progress! Lots of interesting data and statistics to come.