Search Unity

  1. Get all the Unite Berlin 2018 news on the blog.
    Dismiss Notice
  2. Unity 2018.2 has arrived! Read about it here.
    Dismiss Notice
  3. Improve your Unity skills with a certified instructor in a private, interactive classroom. Learn more.
    Dismiss Notice
  4. ARCore is out of developer preview! Read about it here.
    Dismiss Notice
  5. Magic Leap’s Lumin SDK Technical Preview for Unity lets you get started creating content for Magic Leap One™. Find more information on our blog!
    Dismiss Notice
  6. Want to see the most recent patch releases? Take a peek at the patch release page.
    Dismiss Notice

How to make unity ads show every 3 death? Please be specific, thank you.

Discussion in 'Unity Ads' started by Wupeixun, Jun 4, 2016.

  1. Wupeixun

    Wupeixun

    Joined:
    Apr 15, 2016
    Posts:
    7
    I have the default unity ads set, which is shown once every time the "GameOver" scene is loaded. The user's feedback are saying its too much! I would like to set the ads so they are shown once every three times the "GameOver" scene is loaded, please be specific and detailed, I am not very good at C#. Thanks.
    This is my script.
     

    Attached Files:

    • ads.cs
      File size:
      364 bytes
      Views:
      291
  2. rasmus-unity

    rasmus-unity

    Unity Technologies

    Joined:
    Aug 15, 2014
    Posts:
    1,080
    If I've understood you correctly, this should do it:


    Code (CSharp):
    1. using UnityEngine;
    2. using UnityEngine.Advertisements;
    3.  
    4. public class Ads : MonoBehaviour
    5. {
    6.     static int loadCount = 0;
    7.  
    8.     void Start()
    9.     {
    10.         if (loadCount % 3 == 0)  // only show ad every third time
    11.         {
    12.             ShowAd ();
    13.         }
    14.         loadCount++;
    15.     }
    16.  
    17.     public void ShowAd()
    18.     {
    19.         if (Advertisement.IsReady())
    20.         {
    21.             Advertisement.Show();
    22.         }
    23.     }
    24. }
    Let me know if it works.

    -Rasmus
     
    Gurkirt13 likes this.
  3. Wupeixun

    Wupeixun

    Joined:
    Apr 15, 2016
    Posts:
    7
    It worked perfectly, thank you sooo much! your a legend!
     
    rasmus-unity likes this.
  4. phyzikalgamer

    phyzikalgamer

    Joined:
    Aug 25, 2016
    Posts:
    3
    how did you trigger this script?

    did you just put it on a game object or on a button or something?

    (im a real noob sorry)
     
  5. rasmus-unity

    rasmus-unity

    Unity Technologies

    Joined:
    Aug 15, 2014
    Posts:
    1,080
  6. phyzikalgamer

    phyzikalgamer

    Joined:
    Aug 25, 2016
    Posts:
    3
  7. phyzikalgamer

    phyzikalgamer

    Joined:
    Aug 25, 2016
    Posts:
    3
    Sorry one quick question i have this setup and it works well (I changed to every 6 loads) only issue i have it when i click start game it plays add then i die 6 times then it loads.

    Its like it always plays the ad once first then every 6 times. Is there a way to stop it playing the first time and only after the first x number of deaths
     
  8. MrDasixMr

    MrDasixMr

    Joined:
    Feb 15, 2015
    Posts:
    49

    Code (CSharp):
    1. using UnityEngine;
    2. using UnityEngine.Advertisements;
    3. public class ads : MonoBehaviour
    4. {
    5.     static int loadCount = 1;
    6.     void Start()
    7.     {
    8.         if (loadCount % 6+1 == 0)  // only show ad every third time
    9.         {
    10.             ShowAd ();
    11.         }
    12.         loadCount++;
    13.     }
    14.     public void ShowAd()
    15.     {
    16.         if (Advertisement.IsReady())
    17.         {
    18.             Advertisement.Show();
    19.         }
    20.     }
    21. }
     
  9. CaliforniumGames

    CaliforniumGames

    Joined:
    Mar 13, 2017
    Posts:
    1
    There is a better way to do it, this way it will continue counting without resetting the timer this is a better one

    static int loadCount = 0;

    void Start()
    {

    if (loadCount == 4)
    {
    loadCount = 0;
    ShowAd();
    }
    else
    {
    loadCount++;
    }


    }

    public void ShowAd()
    {
    if (Advertisement.IsReady())
    {
    Advertisement.Show();
    }
    }
     
  10. IcyBot

    IcyBot

    Joined:
    May 4, 2017
    Posts:
    5
    Great thread, solved the issue I was having.

    Having to say that coming from someone that has no real knowledge of coding the Unity Tutorials and Community has been invaluable.
     
    UnitySwift7 likes this.
  11. 4topappstoday

    4topappstoday

    Joined:
    Feb 3, 2016
    Posts:
    3
    Hello Guys
    I'm also not very familiar with showing ads
    I have successfully showed unity ads with the method in the first comments thanks to rasmus-unity and NikolaTotev
    but I still struggle with other network ads such as admob and chartboost, Their SDK is kind of hard to me.
    I want to do the same thing with admob (Showing Interstitial Ads After 3 gameplays), I'm using a plugin from unity asset store called "very easy ads" but i still can't implement ads correctly.
    If someone already did what i want to do, please help me show ads too
     
  12. incenseman

    incenseman

    Joined:
    Nov 20, 2012
    Posts:
    66
    I do not understand "resetting the timer". What timer and what function does it serve?
     
  13. incenseman

    incenseman

    Joined:
    Nov 20, 2012
    Posts:
    66
    I have reopened my game to try getting ads to work and cannot even get started on ads because of this error.
    "UnityException: Transform child out of bounds
    PlayerScript.CreateAtStart (Int32 amount) (at Assets/Walls/Scripts/PlayerScript.cs:297)
    PlayerScript.Start () (at Assets/Walls/Scripts/PlayerScript.cs:66)"
    methos5k tried to help but nothing seems to work.
    Link to that thread : https://forum.unity.com/threads/uni...int32-amount-at-assets-w.512450/#post-3352320
     
  14. Carson365

    Carson365

    Joined:
    Nov 8, 2017
    Posts:
    42
  15. incenseman

    incenseman

    Joined:
    Nov 20, 2012
    Posts:
    66
    I rebuilt my game from scratch.
    No more player script error.
    I am now getting the following error using the script by rasmus-unity.
    "
    UnityAdsEditor: Initialize(gameID, True);
    UnityEditor.Advertisements.UnityAdsEditor:EditorOnLoad()"

    The test ad does not show.
    I have build setting to use Android.

    Is there a way to fix this?
    I am using Unity 5.6.5f1
     
  16. rasmus-unity

    rasmus-unity

    Unity Technologies

    Joined:
    Aug 15, 2014
    Posts:
    1,080
    @incenseman, are you using Asset Store or engine integrated version of Ads SDK? And what do you mean by errors, does they have the red error icon next to them (looks like those messages are from Console window in editor)

    /Rasmus
     
  17. incenseman

    incenseman

    Joined:
    Nov 20, 2012
    Posts:
    66
    I am using the integrated ads SDK. It is in from Console window in editor and has an exclamation point in a white text bubble like from a comic strip.

    I have removed all ad related scripts and still get the same thing.
    The only way I do not see this issue is when ads are off.

    Re-added your script and now am getting this:
    "error CS0234: The type or namespace name `Advertisements' does not exist in the namespace `UnityEngine'. Are you missing an assembly reference?"

    Here is the line of code that takes me to:
    Code (csharp):
    1. using UnityEngine.Advertisements;
     
    Last edited: Jan 15, 2018
  18. rasmus-unity

    rasmus-unity

    Unity Technologies

    Joined:
    Aug 15, 2014
    Posts:
    1,080
  19. Carson365

    Carson365

    Joined:
    Nov 8, 2017
    Posts:
    42
    Whats the "intregate ads SDK" ? I'm confused with that I think.
    Thanks.
     
  20. rasmus-unity

    rasmus-unity

    Unity Technologies

    Joined:
    Aug 15, 2014
    Posts:
    1,080
  21. Carson365

    Carson365

    Joined:
    Nov 8, 2017
    Posts:
    42
    Sorry. Should of read that page better.
    Thanks!
     
  22. incenseman

    incenseman

    Joined:
    Nov 20, 2012
    Posts:
    66
    Now I try to add your script to an empty GameObject and get this:

    I feel that I am so close to getting this to work! :)
     
  23. Carson365

    Carson365

    Joined:
    Nov 8, 2017
    Posts:
    42
    Make sure the part where it says "public class NAMEOFSCRIPT : MonoBehaviour", that your NameOfScript is the exact same as the actualy script name in the Unity editor. That's usually what I do when I get that error.
     
  24. incenseman

    incenseman

    Joined:
    Nov 20, 2012
    Posts:
    66
    Huh?
     
  25. Carson365

    Carson365

    Joined:
    Nov 8, 2017
    Posts:
    42
    Your script.
    Code (CSharp):
    1. using UnityEngine;
    2.  
    3. public class EXAMPLE : Monobehaviour
    4.  
    5. void Start () {
    6. blahblahblah
    7. }
    8.  
    Make sure on your script, the "EXAMPLE" part matches with your script name
     
  26. incenseman

    incenseman

    Joined:
    Nov 20, 2012
    Posts:
    66
    That worked like a charm! I do understand a lot of the jargon but I am learning.....slowly. :)
    Thanks a ton!!!!!!
     
  27. Carson365

    Carson365

    Joined:
    Nov 8, 2017
    Posts:
    42
    Glad you got it to work!