In this course I am learning many things, one of them is the addition of Ads in the game that without wasting too much time I start right away.
We start with Unity, we have to create a button that allows us to launch the advertisement
always on unity is necessary to open the window of the services of unity to enable ads, to do this you must have an authenticated Unity account on the web browser and start with the required configurations, nothing special just follow the instructions and fill in the necessary fields.
Now if you also have a button “Go to dashboard” in the service panel under the Ads, this allows you to go and get the necessary data that we need as soon as we move to the code.
As for the other managers, I create an empty Game Object and assign it a script with the same name and let’s move on to the code.
Our class “AdsManager” will take care of almost everything, it will oppose the other managers to access the player or update the UI, but its main task is to make the reward work properly after the advertisement.
To do this we need to add a library related to Advertisement and implement an interface that allows us to proceed.
the implementation of this interface forces us to implement 4 methods, we will use mainly two of them.
let’s go in order as the first thing we must define the variables that we are going to take from our dashboard and connect them to the corresponding event in the Start method.
The methods that concern us are two, the first allows us to define if everything is ready, the second is the behavior that must follow at the end, and to define it better I used a switch to scan the three possible states.
Finally, the last method that we will write is the one that we will bind to the button itself in its OnClick listener.
Remember to enable the test mode in the services to try it in the editor and this should be the result.
All the material to deepen or see the examples you can recover on this link