Search Unity

  1. Megacity Metro Demo now available. Download now.
    Dismiss Notice
  2. Unity support for visionOS is now available. Learn more in our blog post.
    Dismiss Notice

Show Unity Ads After Every 5 Deaths in Game

Discussion in 'Unity Ads & User Acquisition' started by jrivis, Oct 8, 2015.

  1. jrivis

    jrivis

    Joined:
    Oct 6, 2015
    Posts:
    5
    Hello,

    I just recently got basic Unity ads to work at the end of every death. And now I'm trying to make them show up on every 5th death so that it doesn't bombard the user.
    Would anyone be able to help me with this?

    Thanks in advanced! :)
     
  2. Salazar

    Salazar

    Joined:
    Sep 2, 2013
    Posts:
    235
    Hello @jrivis

    Hope this code helps.

    Code (CSharp):
    1.  
    2. ...
    3. private int deadcount;  // Player dead count.
    4. void Start()
    5. {
    6. deadcount=0;  
    7. }
    8. public void OnDead()
    9. {
    10. // If player deads first time we show the ad and add 1 to our counter.
    11. if(deadcount==0)
    12. {
    13. ShowAd();
    14. deadcount+=1;
    15. }
    16. // We reset counter after 5 deads
    17. else if (deadcount==4)
    18. {
    19. deadcount=0;
    20. }
    21. }
    22.  
    23.  
    Regards,
     
    jrivis likes this.
  3. jrivis

    jrivis

    Joined:
    Oct 6, 2015
    Posts:
    5
    Hello @Salazar ,

    Thanks heaps for getting back to me :)

    I tried adding this code you have given me to my gameover script. But it seemed to have made the ads not load at all.
    I could be inserting it into the wrong section though :/

    I have uploaded my current Gameover script that loads my ads every gameover, just for reference if that may help? :)
     

    Attached Files:

  4. Salazar

    Salazar

    Joined:
    Sep 2, 2013
    Posts:
    235
    Hello @jrivis ,

    Having two monobehaviour classes on same script is not a good practice i think. (ref.)

    I am seperating my gamemanager script and admanager script and using C# singleton feature to communicate each other.

    You should check scripting with unity tutorials. www.unity3d.com

    I am not a pro at coding, so I dont want to miss guide you at the very basics.

    Regards,