- Home /
Help displaying unity ads
I have a problem with displaying unity ads on a game I'm working on. The game automatically re-spawns the player whenever he dies, so I would like for an ad to be displayed, lets say, after every 5 re-spawns. Any help would be greatly appreciated.
Answer by corn · Jan 05, 2016 at 12:45 PM
UnityAds is fairly easy to use. You should probably check UnityAds' knowledge base, the Manual page and the Scripting API page if you're confused about how to display an ad.
This kind of script should do the trick for what you're trying to achieve.
int playerNumberOfRespawns = 0;
void Respawn()
{
// ... actual respawn code here
// Displaying ads
playerNumberOfRespawns++;
if (playerNumberOfRespawns % 5 == 0 && Advertisement.IsReady())
{
Advertisement.Show();
}
}
Also keep in mind that no ad will show in the editor, this will only work on iOS or Android builds.
Thank you very much, I will try to implement your script. I really didn't think on implementing it that way :D... Again, thank you :)
This is the code I'm using... I'm running it in an update function... the ads are showing, but the game still continues to run in the background... not sure how to fix it ( kinda rusty program$$anonymous$$g :( )... any help? at least to guide me in the right direction?
void Update ()
{
// If the player has died
if (playerDead)
{
// Stop the camera movement
cameraVelocity.speed = 0f;
numberOfRespawns ++;
if (numberOfRespawns % 5 == 0 && Advertisement.IsReady ()) {
showAd = true;
Advertisement.Show ();
}
if (!newGame && showAd == false)
{
// We are now ready to start a new game
newGame = true;
// StartCoroutine needed to allow time
// for the particle effects to finish
StartCoroutine(GameStart());
// Get the player score
playerScore = score.score;
// Pass the score to the method Highscore
Highscore(playerScore);
}
}
}
Well if it's about enemies, if I were you I'd make a static variable like pause and would set it to true when you are displaying the ads. Also I'd check if pause is false in your character AI and/or hero script and I'd only let these scripts to execute their code when pause is false. as for the other parts in the game, objects that don't move don't need to be checked.
Another approach would be setting Time.TimeScale
to 0, while you're showing the ad, which makes the games' time stop and then you couldset it back to 1.0 when you finished showing the ad.
Answer by AlvinFassari · Jan 13, 2016 at 06:57 PM
Dont you need to sign the GameID to show ads?
Since Unity 5.2 (I think) the services tab takes care of things like the gameID.
But you shouldn't have made your post an answer, it should be converted to a comment.