- Home /
how to design a "remove ads" option in android unity game?
Hi,
how to design a "remove ads" option in android unity game? I have been searching but cannot see any sample code, does anyone have any advise on how to do this?
Thanks, Kim
Answer by keburanuil · Jul 29, 2014 at 11:59 PM
I did it in my game simple by using playerprefs. If player buys/uses "remove ads"-option, save it in playerprefs and destroy all ad-objects and events. Every time you start the game, check if player has the adfree version and if player has then don't setup ads.
function Awake()
{
SetupAds();
}
function SetupAds()
{
if(PlayerPrefs.HasKey("AdFree"))
return;
// Setup your ads here
}
function RemoveAds()
{
if (PlayerPrefs.HasKey("AdFree"))
print("Ads already removed");
else{
PlayerPrefs.SetInt("AdFree", 1);
PlayerPrefs.Save();
// destroy/disable all your ad objects here
}
}
function RestorePurchases()
{
if (IsProductPurchased("ProductId"))
RemoveAds();
}
But if the player clear the application data, the player prefs will be lost. And the Ads will appear again. I would advise to store this information somewhere else and make a "restore purchase" option just in case :)
Thanks for the great feedback, @ agoVitor_r , where eklse could you store this data? on a DB of your own, remotely?
If you use google's in-app purchasing, google stores your every purchase.
http://forum.unity3d.com/threads/released-android-native-plugin.201468/
In this plugin you can simply check every purchase using method:
public bool IsProductPurchased(string S$$anonymous$$U)
So you would create a restore purchase button and then check if the product is bought.
I purchased the asset on http://forum.unity3d.com/threads/released-android-native-plugin.201468/ , but it seems like a lot is going on there, could I ask how would you use: public bool IsProductPurchased(string S$$anonymous$$U) in the sample script that given earlier? Any help would be much appreciated, it would be nice as it is a nice a simple piece of code but I do not understand the IsProductPurchased(string S$$anonymous$$U) yet, how to use, what does it do?
Thanks for any help provided.
Actually you have to do your billing/ad -manager in c#. $$anonymous$$y script was just a simulation how I desinged my "remove ads"-option.
However if you use js, you can make one c# script that has methods like RestorePurchases() and call them from js using Send$$anonymous$$essage().
// This should print false unless you have purchased product: "abc123"
print(AndroidInAppPurchase$$anonymous$$anager.instance.inventory.IsProductPurchased("abc123"));
Your billing manager would look like this:
public class Example : $$anonymous$$onoBehaviour{
// Add all methods you need.
// Call methods from js using Send$$anonymous$$essage().
public void RestorePurchases()
{
if (AndroidInAppPurchase$$anonymous$$anager.instance.inventory.IsProductPurchased("abcd12345"))
// Remove ads
}
}
Read this for more information: https://docs.google.com/document/d/1px0BVXcZqgrW99OQV4b$$anonymous$$7q1rD5NYaCYTxXnn4eS4ytY/edit#
Your answer
Follow this Question
Related Questions
Admob works on an empty project but not on my actual project 0 Answers
Making Money with Unity Ads 1 Answer
can you please write rewarded ad script 0 Answers
Vungle Ads Not Showing For One Specific Package Name 0 Answers
Android Ads Error 2 Answers