UNITY ADS (+ rewarded ads) - Monetize your mobile games!

Video Statistics and Information

Video
Captions Word Cloud
Reddit Comments

This post appears to be a direct link to a video.

As a reminder, please note that posting footage of a game in a standalone thread to request feedback or show off your work is against the rules of /r/gamedev. That content would be more appropriate as a comment in the next Screenshot Saturday (or a more fitting weekly thread), where you'll have the opportunity to share 2-way feedback with others.

/r/gamedev puts an emphasis on knowledge sharing. If you want to make a standalone post about your game, make sure it's informative and geared specifically towards other developers.

Please check out the following resources for more information:

Weekly Threads 101: Making Good Use of /r/gamedev

Posting about your projects on /r/gamedev (Guide)

I am a bot, and this action was performed automatically. Please contact the moderators of this subreddit if you have any questions or concerns.

šŸ‘ļøŽ︎ 1 šŸ‘¤ļøŽ︎ u/AutoModerator šŸ“…ļøŽ︎ Apr 26 2021 šŸ—«︎ replies
Captions
so you've just completed creating your game and are ready to publish it but wait let's first add some ads to earn that sweet ad revenue there are multiple art providers for unity games but in this episode we'll focus on unity monetization services that support both ios and android i will show you how to easily set it up and add it to your project finally you'll learn what the different ad placements are and the best use cases for them let's go so this is our test scene for now it only has a few buttons that will allow us to demo everything but at the end of the video i'll show a more real-life example to start working with unity ads we need to enable them for our project the best way to do it is to select window at the very top and choose general services you'll see this new services tab that usually opens on the right side of the unity here we need to create a new unity project id select your organization and click create if you don't see that option make sure you are logged in into unity by clicking the account button at the top and selecting sign in on the updated screen let's select ads and turn them on using this toggle select this option only if your app is targeted to children under age 13 and click continue as you can see ad service is now turned on and unity should install a new package called advertisement this will allow us to integrate ads into our game code please make sure it is installed click at the very top window package manager and check if you can see a tick mark next to the advertisement package if not install it in the next step we'll create the build target of our game because unity ads are only supported on ios and android we need to make sure that we're developing for the right platform at the very top select file build settings here instead of the pc mac and linux option select either ios or android and click switch platform switching platforms may take a while especially if you haven't used the platform with your project before you'll know that the process is ready when the unity logo shows up next to the selected platform great the last step will be to turn on ads on the web platform in the services tab in the unity click on the go to dashboard button on the website that just appeared select your project and you should be presented with the placement options here you can specify how when and where your ads will be shown in your game we can split that to three categories interstitial ads usually play between game levels without any reward to the player by default they are skippable after 5 seconds rewarded arts the most profitable odds are displayed if user clicks something like double your score after finished level they are non-skippable and after successful play we should somehow reward our player for watching it and finally the banners that are just displayed somewhere on the screen and they can be tapped by the player to learn more as you can see by default we have already two art types set up video and rewarded video because i'd like to show you all the ad placements in this video i will quickly click add placement button name it banner select the banner option and created that way we have all three art types prepared remember those art types ids and the game ids listed on the left we'll need them in just a second okay time to code in some ads into our game let's add a new script to the canvas or to the main camera called ads manager open it because we'll be using the advertisement package at the very top of our file type using utengine.advertisements before showing any ets we'll need to initialize the system in the start method type advertisement dot initialize and open parenthesis here we need to pass in the game id from the list in the ads dashboard if you're targeting only for one platform that's easy simply paste in your game id here as a string but if you're targeting both platforms we need to use a small trick that would switch this id depending on the platform we are running at the top of our class type hashtag if in capital unity underscore ios string game id equals and here paste in correct string for ios then press return and type hashtag else string game id equals correct string for android and finally hashtag and if that bit of code will run depending on the current platform for example i've set the build target for ios just a minute ago and everything under else is grayed out and won't be executed the last step will be to replace that hard hard-coded string with the game id variable great now save the script go back to unity run the game and check for any console messages if the console is empty that's great unity ads are successfully connected but if you're seeing errors like this make sure that you're logged in and that you have entered the correct game ids now let's create our first ad we'll start with the interstitial one which is being played without an interaction from the user in our script create a new method public void play add open brackets just before showing the ad we need to check if the video is ready to do so type if advertisement dot is ready and passing the name of the ad so in our case just video then open brackets advertisement that show and again passing the name of our ad actually that's it in unity just for demo purposes we'll use this button to trigger method we've just created select it drag in game object where ads manager is attached to to the on click event and from the drop down select ads manager play art now if we run the game you can see that after we press the button a new screen appears with the advertisement mockup of course in your build game on the actual device that art will be replaced with the actual video okay so now go back to the script and let's do the same with the rewarded ad type public void play rewarded ad open brackets if advertisement that is ready and pass in rewarded video this time open brackets advertisement dot show and passing rewarded video this time we'll also type else open brackets and here specify what should happen if the ad is not yet loaded up i'll just type debug.log rewarded and it's not ready remember that you can get source files for all my unity tutorials by supporting me on patreon link in the description this method will also show us an ad but because this is a rewarded video we'd like to get information on if the user actually have watched it to the end to get that we need to implement a set of built-in callback methods next to the class name and model behavior type comma and then i unity adds listener your code editor should immediately scream at you that there is something wrong that's because we need to implement this interface just right click on it select quick actions and click on the implement interface option that should automatically create four methods for you these methods will be called by unity whenever some actions occur like art started playing we'll be interested in all unity ads that finished this will be a method triggered whenever our ad is completed let's check what kind of art just has been played and if it has been successful type if placement id double equals rewarded video and show result double equals show result dot finished open brackets and here specify what should happen if the rewarded ad has been finished this is the place where you grant some extra coins lives etc for demo purposes i'll just type debug.log player should be rewarded that's it before going back to inti we need to quickly fix those three other methods because currently they will throw an error in ads ready i'll type debug.log ads are ready in adds date error i'll type debug.log error plus message and in ads did start debug.log video started finally in the start method we need to tell unity that here are all the callback methods so type advertisement dot add listener and pass in this that's it for reward dots let's test them out as before i'll need to hook up the second button by dragging in the canvas right here and selecting ads manager play rewarded ad now play our game and run rewarded art as you can see this time we don't have a skip button so we can only close it and by doing so we'll simulate a successful debug log time for the last part banner ads in the script once more create a new method public void show banner open brackets and as always if advertisement dot is ready and passing banner open brackets then advertisement dot banner dot set position and passing banner position dot bottom center to make sure that it will be at the bottom middle and finally advertisement dot banner dot show and passing the placement id so just banner because we like to show our banner at the very start of the game in the start method run our show banner method the problem with this approach is that while your game has some time to load the video for the other ads before playing them the banner might not have enough time to load up and will simply fail this if statement to fix that we'll need to create a curve routine that will basically count up to 1 second and try again below show banner type i enumerator repeat show banner open brackets firstly we need to wait for one second to do that simply type yield return new wait for seconds and passing the amount of seconds in my case just one then finally after one second of waiting trigger our show banner again remember that the curtains run independently from the main game loop so it won't stop your game everything will be done in the background now to run it in the show banner we need to type else so if the banner is not loaded up open brackets start coding and pass in repeat show banner that's almost everything for coding the very last thing will be a method to hide the banner public void hide banner open brackets advertisement dot banner dot hide great now save everything go back to unity and as always assign both buttons first one to show the banner and the second one to hide it time to test out everything press play and click on the first show add button works great then press rewarded add button and this time also everything shows up but without the option to skip the ad after closing it we get a message in the console finally you can see that our banner is visible at the bottom and we can use this button to hide it everything works as expected now at the very end i'll show you how to integrate ads to existing project so here i have a very simple game inspired by a dinosaur in google chrome here are my ideas for the art placements banner art will be visible all the time at the bottom simple ads will be displayed after each game over and the rewarded ads will be displayed if the user clicks double score at the beginning of the gameplay here i have a script called game manager it contains most of the game logic inside of it i have already prepared some efforts that will be useful in just a second so now how do we connect the ads manager script to our game manager so we can call all of the methods from it we need to create a variable reference at the top of this class i'll type public ads manager ads and then in the unity inspector link adds manager to the newly created field in the game manager just like that now we can call all methods from our main script for example at the start i like to call a method that shows the banner to do it simply type adds dot show banner here i have a game over method and as the name suggests it is triggered when a player fails as i mentioned before i'd like to run our play add method here so just type ads dot play ad finally the most complicated one the rewarded art here i have a method called double score that should play the reward dot and after successful competition should run this other method called on rewarded art success but how do we do it by just typing adds that play rewarded ad we won't achieve our goal because we won't know if the user has watched video or not we need to modify our script a bit our play rewarded ad in the ads manager should get the action to run after success so right here specify a new input parameter type action on success as you can see actions shows an error that's because at the very top of our script we need to type using system now let's create a new variable that will store that action at the top of the ads manager class type action on rewarded ad success and back to our method type on rewarded ad success equals on success that way we basically create a variable that stores a whole method that should be triggered after a successful reward add is being shown so finally here in the all unity ads did finish in our if statement we've created before type on rewarded add success dot invoke to run a method trapped inside of this action variable when we finally go to the game manager in the double score method simply type ads.play rewarded ad as before but this time as you can see unity demands to put what should happen after add has been played so simply in the parenthesis type in desired method in this case on rewarded ad success wow that was a lot but everything should be working now so let's test it out on the game start you can immediately see that the bottom banner pops out that's great let's start a game and on the game over the simple ad immediately starts playing now after we close it just before playing the next game we can click on the double score option that shows us an unskippable ad that after finish starts a new game with the score multiplier so that's it thanks a lot to my awesome patrons that support this channel be sure to check out my other videos about unity basics see you soon you
Info
Channel: Coco Code
Views: 26,724
Rating: undefined out of 5
Keywords: unity, cococode, bionicl code, bionicl, unity3d, Maciej maj, tutorial, guide, playfab, coco code, unity ads, rewarded ads, banner ads, interstitial ads, unity admob, unity ads ios, unity ads android, Unity ads dashboard, Creating interstitial ad, Creating rewarded ad, unity analytics, payment, money, earning, game monetization tutorial, how to monetize your game, Unity Ads Tutorial, unity monetization tutorial, unity mobile game ads tutorial, unity monetization, monetize, monetise
Id: Rxpj0nmlmTw
Channel Id: undefined
Length: 18min 29sec (1109 seconds)
Published: Mon Apr 26 2021
Related Videos
Note
Please note that this website is currently a work in progress! Lots of interesting data and statistics to come.