Search Unity

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

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

Thread Status:
Not open for further replies.
  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:
      1,919
  2. rasmus-unity

    rasmus-unity

    Moderator

    Joined:
    Aug 15, 2014
    Posts:
    1,312
    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
     
  3. Wupeixun

    Wupeixun

    Joined:
    Apr 15, 2016
    Posts:
    7
    It worked perfectly, thank you sooo much! your a legend!
     
    Ahmadreda and rasmus-unity like 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

    Moderator

    Joined:
    Aug 15, 2014
    Posts:
    1,312
  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. MrDasix

    MrDasix

    Joined:
    Feb 15, 2015
    Posts:
    64

    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. }
     
    Jointuletz and (deleted member) like this.
  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();
    }
    }
     
    Deleted User likes this.
  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:
    90
    I do not understand "resetting the timer". What timer and what function does it serve?
     
  13. incenseman

    incenseman

    Joined:
    Nov 20, 2012
    Posts:
    90
    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:
    90
    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

    Moderator

    Joined:
    Aug 15, 2014
    Posts:
    1,312
    @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:
    90
    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

    Moderator

    Joined:
    Aug 15, 2014
    Posts:
    1,312
  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

    Moderator

    Joined:
    Aug 15, 2014
    Posts:
    1,312
  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:
    90
    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:
    90
    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:
    90
    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!
     
  28. Ahmadreda

    Ahmadreda

    Joined:
    Dec 24, 2018
    Posts:
    1
    Hi , Ineed let my unity ad show every 3 minute , so ,how can i do this ?
     
    Deleted User and kidtdm like this.
Thread Status:
Not open for further replies.