Search Unity

  1. Welcome to the Unity Forums! Please take the time to read our Code of Conduct to familiarize yourself with the forum rules and how to post constructively.
  2. Dismiss Notice

Remove Ads Call

Discussion in 'Scripting' started by dmarku26, Aug 15, 2020.

  1. dmarku26

    dmarku26

    Joined:
    Aug 3, 2020
    Posts:
    23
    Hi guys, i have been successfully able to integrate AdMob ads on the app that i am developing. I have a banner ad on homepage and also an interstitial ad that shows on gameover. The ads are controlled through a C# Script. I have also installed IAP services on unity and also successfully followed their tutorial to create an IAP to remove ads. Now my question is, what should i call on the line below to actually remove the ads after a player purchases that non consumable item? My understanding is that at the moment it just shows a debug text that Ads are Removed, but it needs the actual code, function to really remove ads. Anyone can help with this?

    public PurchaseProcessingResult ProcessPurchase(PurchaseEventArgs args)
    {
    if (String.Equals(args.purchasedProduct.definition.id, removeAds, StringComparison.Ordinal))
    {
    Debug.Log("Remove All Ads");
    }
    else
    {
    Debug.Log("Purchase Failed");
    }
    return PurchaseProcessingResult.Complete;
    }
     
  2. Yanne065

    Yanne065

    Joined:
    Feb 24, 2018
    Posts:
    175
    Have a bool.. if not purchased show ad and when they buy it just set it to true
     
  3. dmarku26

    dmarku26

    Joined:
    Aug 3, 2020
    Posts:
    23
    Thankn you for your suggestion. I am kinda new to c#, almost 2 weeks now, can you show me how can i implement the bool function there?
     
  4. dmarku26

    dmarku26

    Joined:
    Aug 3, 2020
    Posts:
    23
    I am attaching here the 2 scripts for reference. the Admanager runs the ad (which i have tested and they run like they are suppose to). The IAPManager is where i have the code and where i need to turn of all ads after that product remove ads is purchased.
     

    Attached Files:

  5. Yanne065

    Yanne065

    Joined:
    Feb 24, 2018
    Posts:
    175
    I'm on my phone so I cant open the file on the phone
     
  6. Yanne065

    Yanne065

    Joined:
    Feb 24, 2018
    Posts:
    175
    but yeah when you show ad when you use if statement with the conditions just add && bool
     
  7. dmarku26

    dmarku26

    Joined:
    Aug 3, 2020
    Posts:
    23
    I understand. A little help with the code would be appreciated. I am afraid if i use the bool method, when the player closes the game and opens it again, the ads will show again. I need a method that the ads are gone forever after the player purchases the non consumable remove ads product.
     
  8. Yanne065

    Yanne065

    Joined:
    Feb 24, 2018
    Posts:
    175
    You could just save the value....either with json or binary or playerprefs
    Code (CSharp):
    1. if(playtime %5 == 0 && !purchased)
    2. {
    3.    ShowAd();
    4. }
    When player buy remove ad when you set purchased to true save the value and every time game start read the value from save then you will have your results
     
    Last edited: Aug 16, 2020
  9. dmarku26

    dmarku26

    Joined:
    Aug 3, 2020
    Posts:
    23
    I could not make it work but thank you
     
  10. Yanne065

    Yanne065

    Joined:
    Feb 24, 2018
    Posts:
    175
    Which part ? Saving ?