Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 12 Next capture
2021 2022 2023
1 capture
12 Jun 22 - 12 Jun 22
sparklines
Close Help
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
  • Asset Store
  • Get Unity

UNITY ACCOUNT

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account
  • Blog
  • Forums
  • Answers
  • Evangelists
  • User Groups
  • Beta Program
  • Advisory Panel

Navigation

  • Home
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
    • Blog
    • Forums
    • Answers
    • Evangelists
    • User Groups
    • Beta Program
    • Advisory Panel

Unity account

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account

Language

  • Chinese
  • Spanish
  • Japanese
  • Korean
  • Portuguese
  • Ask a question
  • Spaces
    • Default
    • Help Room
    • META
    • Moderators
    • Topics
    • Questions
    • Users
    • Badges
  • Home /
avatar image
0
Question by dasani2406 · May 16, 2018 at 11:23 PM · adsadmobreferencingunityadscoins

How do I reward the players with coins after they watch a Admob rewarded video?

Ok, I am using the same script that everyone is using, by that I mean the script given by google. I already created an AdMob rewardedVideo Unit and the type is "coins" and the amount is 300

I have not idea how to reference this 300 amount to my coins amount in the game. I am confused and do not know where to go next.

 void Start(){
  // Called when the user should be rewarded for watching a video.
         rewardBasedVideo.OnAdRewarded += HandleRewardBasedVideoRewarded;
 }

 public void HandleRewardBasedVideoRewarded(object sender, Reward args)
     {
         string type = args.Type;
         double amount = args.Amount;
         print("here");
         MonoBehaviour.print("HandleRewardBasedVideoRewarded event received for " + amount.ToString() + " " + type);
     }
 
         public void ShowRewardedVids()
     {
         if (rewardBasedVideo.IsLoaded())
         {
             rewardBasedVideo.Show();
         }
     }



if this help, I usually add coins and save them like that.

  ScoreManager.GetInstance().savecoin += 300;
                 ScoreManager.GetInstance().Save();


Comment
Add comment
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users

1 Reply

· Add your reply
  • Sort: 
avatar image
0

Answer by Nebukam · May 17, 2018 at 12:38 AM

Ok maybe I have missed something in my understanding of your question, but it should only be a matter of adapting the HandleRewardBasedVideoRewarded function like so :

 public void HandleRewardBasedVideoRewarded(object sender, Reward args)
  {
  
       string type = args.Type; //Reward type ("coins" if everything goes fine)
       double amount = args.Amount; //Reward amount (300 or else)
  
       if(type == "coins")
       {
            ScoreManager.GetInstance().savecoin += (int)amount;
            ScoreManager.GetInstance().Save();
       }
  
  }

Comment
Add comment · Show 7 · Share
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users
avatar image dasani2406 · May 17, 2018 at 02:08 AM 0
Share

Hey Nebukam,

It look like your code would work, but when I try to run my game in the editor I do not receive the coins. I decided to include a print("here"); in the event handler to see if the event is firing . And it look like it is not firing as I cannot see the "here" in the console when I press the button to show the video ad.

Why is the event handler not firing? I followed the same code as provided in Google $$anonymous$$obile Ads SD$$anonymous$$ for Unity. I do not see where I could have messed up.

avatar image Nebukam dasani2406 · May 17, 2018 at 02:32 AM 0
Share

Try not calling Advertisement.Initialize(appId); (wherever you're initializing Ad$$anonymous$$ob) it appears Ad$$anonymous$$ob already Initializes Unity Ads, calling it twice will break it, thus preventing the OnAdRewarded event from firing.

avatar image dasani2406 Nebukam · May 17, 2018 at 06:53 AM 0
Share

Hey Nebukam,

it is still not working. I do not get why the event handler is not firing.

this is the start function of the script maybe it can help. Thanks for the help by the way.

  public void Start()
     {
 #if UNITY_ANDROID
        string appId = "ca-app-pub-3940256099942544/5224354917";
 
 #endif
 
         // Initialize the Google $$anonymous$$obile Ads SD$$anonymous$$.
       $$anonymous$$obileAds.Initialize(appId);
 
 
         // Get singleton reward based video ad reference.
         this.rewardBasedVideo = RewardBasedVideoAd.Instance;
 
         // Called when an ad request has successfully loaded.
         rewardBasedVideo.OnAdLoaded += HandleRewardBasedVideoLoaded;
         // Called when an ad request failed to load.
         rewardBasedVideo.OnAdFailedToLoad += HandleRewardBasedVideoFailedToLoad;
         // Called when an ad is shown.
         rewardBasedVideo.OnAdOpening += HandleRewardBasedVideoOpened;
         // Called when the ad starts to play.
         rewardBasedVideo.OnAdStarted += HandleRewardBasedVideoStarted;
         // Called when the user should be rewarded for watching a video.
         rewardBasedVideo.OnAdRewarded += HandleRewardBasedVideoRewarded;
         // Called when the ad is closed.
         rewardBasedVideo.OnAdClosed += HandleRewardBasedVideoClosed;
         // Called when the ad click caused the user to leave the application.
         rewardBasedVideo.OnAdLeavingApplication += HandleRewardBasedVideoLeftApplication;
 
         this.RequestRewardBasedVideo();
     }




Show more comments

Your answer

Hint: You can notify a user about this post by typing @username

Up to 2 attachments (including images) can be used with a maximum of 524.3 kB each and 1.0 MB total.

Follow this Question

Answers Answers and Comments

85 People are following this question.

avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image

Related Questions

Issue with Reward Ad Playing 2 Answers

How do you monetize games for Windows Phone, Windows (PC) and the Web? 0 Answers

Admob reward player after watching video 0 Answers

Ad platform - Appodeal, good or bad? 1 Answer

Is it a good idea to use Admob alongside Unity Ads for banner ads? 0 Answers


Enterprise
Social Q&A

Social
Subscribe on YouTube social-youtube Follow on LinkedIn social-linkedin Follow on Twitter social-twitter Follow on Facebook social-facebook Follow on Instagram social-instagram

Footer

  • Purchase
    • Products
    • Subscription
    • Asset Store
    • Unity Gear
    • Resellers
  • Education
    • Students
    • Educators
    • Certification
    • Learn
    • Center of Excellence
  • Download
    • Unity
    • Beta Program
  • Unity Labs
    • Labs
    • Publications
  • Resources
    • Learn platform
    • Community
    • Documentation
    • Unity QA
    • FAQ
    • Services Status
    • Connect
  • About Unity
    • About Us
    • Blog
    • Events
    • Careers
    • Contact
    • Press
    • Partners
    • Affiliates
    • Security
Copyright © 2020 Unity Technologies
  • Legal
  • Privacy Policy
  • Cookies
  • Do Not Sell My Personal Information
  • Cookies Settings
"Unity", Unity logos, and other Unity trademarks are trademarks or registered trademarks of Unity Technologies or its affiliates in the U.S. and elsewhere (more info here). Other names or brands are trademarks of their respective owners.
  • Anonymous
  • Sign in
  • Create
  • Ask a question
  • Spaces
  • Default
  • Help Room
  • META
  • Moderators
  • Explore
  • Topics
  • Questions
  • Users
  • Badges