• 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 carmanroofer93 · Dec 06, 2020 at 09:37 PM · unity ads

Getting rewarded ads to work 'Unity ads'

I just don't understand what I'm doing wrong, I have my ad script and everything seems to be in check but when i click on the buttons (first ad the play ad button disappears but no coins rewards) (second is when you die in game has a button to watch ads for double coins but nothing happens , its a separate script but basically the same just for a different scene so I'm only posting one script ) am i forgetting to add some code or do i need another script to make this one work. i always thought i needed my gameid from unity dashboard but whenever i tried adding it to my code i just recieved errors, and when i looked online appearently everything is automated so im just confused at this point, thank you for any help i really do appreciate it.

(update) I bought an asset from the store, this and an identical script came with it, the only difference in the other script is instead of rewardedadsmenu its rewardedadsplay, the script is obviously a little old since it uses deprecated code, but appearently everything is good with it, i just cant seem to figure out why it doesn't work) if i need to post anything else to help recieve an answer i will not hesitate. thank you again.

 using System.Collections;
 using System.Collections.Generic;
 using UnityEngine;
 using UnityEngine.UI;
 using UnityEngine.Advertisements;
 
 public class RewardedAdsMenu : MonoBehaviour {
   public SoundManager sm;
     public GameObject PickReward;
   int CoinsBonus;
   int CoinsAds;
   int WatchAds;
   int CoinsAdsZzz;
 
   public void ShowRewardedAd()
   {
     if (Advertisement.IsReady("rewardedVideo"))
     {
       var options = new ShowOptions { resultCallback = HandleShowResult };
       Advertisement.Show("rewardedVideo", options);
     }
   }
 
   private void HandleShowResult(ShowResult result)
   {
     switch (result)
     {
       case ShowResult.Finished:
         Debug.Log("The ad was successfully shown.");
         sm = GameObject.Find("PlayZone").GetComponent<SoundManager>();  
         WatchAds = PlayerPrefs.GetInt("WatchAds",0);  
         CoinsAds = PlayerPrefs.GetInt("CoinsAds", 100);
         CoinsBonus = PlayerPrefs.GetInt("ShipCoinBonus", 1);
         CoinsAdsZzz = CoinsAds*CoinsBonus;
         PlayerPrefs.SetInt("CoinsAdsZzz", CoinsAdsZzz);
           PickReward.SetActive(true);
         WatchAds++;
         PlayerPrefs.SetInt("GetRewardCoins",1);
         PlayerPrefs.SetInt("WatchAds",WatchAds);  
         sm.PlaySound(0);
         break;
       case ShowResult.Skipped:
         Debug.Log("The ad was skipped before reaching the end.");
         break;
       case ShowResult.Failed:
         Debug.LogError("The ad failed to be shown.");
         break;
     }
   }


might as well add the other script :)

 using System.Collections;
 using System.Collections.Generic;
 using UnityEngine;
 using UnityEngine.UI;
 using UnityEngine.Advertisements;
 
 public class RewardedAdsPlay : MonoBehaviour {
   public SoundManager sm;
   public int DoubleCoins;
   public Text DoubleCoinsText;
   public GameObject DoubleCoinBtn;
     public GameObject NeDoubleCoinBtn;
     public GameObject DoubleNextBtn;
   int CoinsC;
   int WatchAds;
 
   public void ShowRewardedAd()
   {
     if (Advertisement.IsReady("rewardedVideo"))
     {
       var options = new ShowOptions { resultCallback = HandleShowResult };
       Advertisement.Show("rewardedVideo", options);
     }
   }
 
   private void HandleShowResult(ShowResult result)
   {
     switch (result)
     {
       case ShowResult.Finished:
         Debug.Log("The ad was successfully shown.");
         sm = GameObject.Find("PlayZone").GetComponent<SoundManager>();  
             CoinsC = PlayerPrefs.GetInt("Coins",0);    
         WatchAds = PlayerPrefs.GetInt("WatchAds",0);  
         DoubleCoins = PlayerPrefs.GetInt("CoinsForGame", 0);
         CoinsC = PlayerPrefs.GetInt("Coins",0);  
         CoinsC += DoubleCoins;
         DoubleCoins += DoubleCoins;
         DoubleCoinsText.text = DoubleCoins.ToString();
             WatchAds++;
         PlayerPrefs.SetInt("WatchAds",WatchAds);  
         PlayerPrefs.SetInt("Coins",CoinsC); 
         DoubleCoinBtn.SetActive(false);
             NeDoubleCoinBtn.SetActive(false);
             DoubleNextBtn.SetActive(true);
         PlayerPrefs.SetFloat("TimerDouble", 120);
         sm.PlaySound(4);
         break;
       case ShowResult.Skipped:
         Debug.Log("The ad was skipped before reaching the end.");
         break;
       case ShowResult.Failed:
         Debug.LogError("The ad failed to be shown.");
         break;
     }
   }
 }
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

2 Replies

· Add your reply
  • Sort: 
avatar image
0
Best Answer

Answer by carmanroofer93 · Dec 09, 2020 at 08:27 AM

@ahmedaniss I appreciate the video tutorial but all that did was show me to copy and paste from unity code samples,

Comment
Add comment · Show 1 · 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 carmanroofer93 · Dec 09, 2020 at 09:15 PM 0
Share

I solved the issue on my own,

 void Start()
     {
         Advertisement.Initialize(gameId);
     }

was all i needed to add before anything else

avatar image
0

Answer by ahmedaniss · Dec 09, 2020 at 01:33 AM

problem fixed here : https://youtu.be/_0z0sPw688A

Comment
Add comment · 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

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.

Welcome to Unity Answers

If you’re new to Unity Answers, please check our User Guide to help you navigate through our website and refer to our FAQ for more information.

Before posting, make sure to check out our Knowledge Base for commonly asked Unity questions.

Check our Moderator Guidelines if you’re a new moderator and want to work together in an effort to improve Unity Answers and support our users.

Follow this Question

Answers Answers and Comments

142 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 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

how back button works in unity calculator? 0 Answers

Detect if a Unity Ad is clicked 0 Answers

unity app crashes when admob banner ad is requested but works fine for interstitial and video ad 0 Answers

Sharing game link and get rewards when contacts install the game on social apps 1 Answer

does anyone know why my game gets a surge of ads impressions From china ? is this normal? 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