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 /
  • Help Room /
avatar image
0
Question by Volosnya · Aug 05, 2018 at 04:07 PM · adsadmob

AdMob Rewarded Video

I'm trying to make it so that you can pass the level by watching rewarded ad.

 using System.Collections;
 using System.Collections.Generic;
 using UnityEngine;
 using GoogleMobileAds.Api;
 using GoogleMobileAds;
 using System;
 
 public class AdManager : MonoBehaviour
 {
 
     public GameManager gm;
 
     public RewardBasedVideoAd rewardVideo;
 
     public int adHasBeenShown;
 
     public void Start()
     {
         adHasBeenShown = 0;
 
         this.rewardVideo = RewardBasedVideoAd.Instance;
 
         rewardVideo.OnAdRewarded += HandleRewardVideoRewarded;
         rewardVideo.OnAdFailedToLoad += HandleOnAdFailedToLoad;
         rewardVideo.OnAdClosed += HandleRewardVideoClosed;
 
         this.RequestRewardVideoo();
     }
 
     public void RequestRewardVideoo()
     {
 #if UNITY_ANDROID
         string rewardedAdID = "ca-app-pub-3940256099942544/5224354917";
 #else
         string rewardedAdID = "unexpected_platform";
 #endif
         AdRequest request = new AdRequest.Builder().Build();
 
         this.rewardVideo.LoadAd(request, rewardedAdID);
     }
 
     public void OnCompleteButtonPressed()
     {
         if (rewardVideo.IsLoaded())
         {
             rewardVideo.Show();
         }
     }
 
     public void HandleRewardVideoRewarded(object sender, Reward args)
     {
         gm.CompleteLevel();
     }
 
     public void HandleOnAdFailedToLoad(object sender, AdFailedToLoadEventArgs args)
     {
         this.RequestRewardVideoo();
     }
 
     public void HandleRewardVideoClosed(object sender, EventArgs args)
     {     
         this.RequestRewardVideoo();
     }
 
 }

gm.CompleteLevel() looks like this:

 using System.Collections;
 using System.Collections.Generic;
 using UnityEngine;
 using System.Linq;
 using UnityEngine.UI;
 using DG.Tweening;
 
 public class GameManager : MonoBehaviour {
 
     public void CompleteLevel()
     {
         foreach (GameObject go in AllSymbols)
         {
             go.GetComponent<AllSymbolsScript>().canMove = true;
             go.GetComponentInChildren<Text>().color = new Color32(255, 255, 255, 255);
         }
 
         foreach (GameObject go in UncorrectSymbols)
         {
             go.GetComponentInParent<Button>().interactable = true;
             go.SetActive(true);
         }
 
         if (!currentLevel.Completed)
             money += 2;
 
 
         moneyText.text = money.ToString();
 
         foreach (GameObject go in CurrSymbols)
         {
             if (go.GetComponent<CurrentCells>().selfChar != null)
             {
                 go.GetComponent<CurrentCells>().selfChar.GetComponent<AllSymbolsScript>().ReturnToHome();
             }
 
             Destroy(go);
         }
 
         LevelDonePanel.alpha = 1;
         LevelDonePanel.blocksRaycasts = true;
 
         currLevel += 1;
 
         levelText.text = "Уровень: " + currLevel;
 
         bM.DisableGamePanel();
         nlS.LevelDone();  
     }
 }
 

The ad comes up, I wait until it's over, and I close it. All that is in the script works fine, except bM.DisableGamePanel() and nlS.LevelDone(). These two methods are not called.

 using System.Collections;
 using System.Collections.Generic;
 using UnityEngine;
 using UnityEngine.UI;
 
 public class ButtonManager : MonoBehaviour {
 
     public LevelPanelManager LPM;
 
     public AudioManager audioManager;
 
     public CanvasGroup friendHelpPanel;
     public CanvasGroup PodskazkiPanel;
     public CanvasGroup levelPanel;
     public CanvasGroup moneyPanel;
     public CanvasGroup gamePanel;
     public CanvasGroup currSymbolPanel;
     public CanvasGroup keyboardPanel;
     public Button soundButton;
     public Sprite soundOnImage;
     public Sprite soundOffImage;
     public bool soundBool = true;
 
     public void DisableGamePanel()
     {
         audioManager.Play("MenuOpen1");
         audioManager.Play("MenuOpen2");
         gamePanel.alpha = 0;
         gamePanel.blocksRaycasts = false;
         currSymbolPanel.alpha = 0;
         currSymbolPanel.blocksRaycasts = false;
         keyboardPanel.alpha = 0;
         keyboardPanel.blocksRaycasts = false;
     }
 }

 public class NextLevelScript : MonoBehaviour {
 
     public Image image;
     public GameManager gm;
     public Text nameText;
     public GameObject moneyText;
     public AudioManager audioManager;
 
     public void LevelDone()
     {
         audioManager.Play("Win");
         image.sprite = gm.currentLevel.image;
         nameText.text = gm.currentLevel.name;
 
         if (gm.currentLevel.Completed)
             moneyText.SetActive(false);
         else
             moneyText.SetActive(true);
 
         gm.currentLevel.Completed = true;
     }
 
 }

If I just bind a method CompleteLevel() to a button and call it, everything works fine.

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 Volosnya · Aug 05, 2018 at 09:26 PM

If anyone ever needs it. I solved it using coroutine

 public void OnCompleteButtonPressed()
     {
         if (rewardVideo.IsLoaded())
         {
             rewardVideo.Show();
         }
         else
         {
             //Display error window
             this.RequestRewardVideoo();
         }
     }
 
     public void HandleRewardVideoRewarded(object sender, Reward args)
     {
         gm.CompleteLevel();
     }


 public void CompleteLevel()
     {
         bM.PodskazkiPanel.alpha = 0;
         bM.PodskazkiPanel.blocksRaycasts = false;
 
         StartCoroutine(CompleteLevelSecondPhase());
     }
 
 public IEnumerator CompleteLevelSecondPhase()
     {
         yield return new WaitForSeconds(0.1f);
 
         foreach (GameObject go in AllSymbols)
         {
             go.GetComponent<AllSymbolsScript>().canMove = true;
             go.GetComponentInChildren<Text>().color = new Color32(255, 255, 255, 255);
         }
 
         foreach (GameObject go in UncorrectSymbols)
         {
             go.GetComponentInParent<Button>().interactable = true;
             go.SetActive(true);
         }
 
         if (!currentLevel.Completed)
             money += 2;
 
 
         moneyText.text = money.ToString();
 
         foreach (GameObject go in CurrSymbols)
         {
             if (go.GetComponent<CurrentCells>().selfChar != null)
             {
                 go.GetComponent<CurrentCells>().selfChar.GetComponent<AllSymbolsScript>().ReturnToHome();
             }
 
             Destroy(go);
         }
 
         LevelDonePanel.alpha = 1;
         LevelDonePanel.blocksRaycasts = true;
 
         currLevel += 1;
 
         levelText.text = "Уровень: " + currLevel;
 
         bM.DisableGamePanel();
         nlS.LevelDone();
     }



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.

Follow this Question

Answers Answers and Comments

151 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 avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image

Related Questions

Interstitial Ads Network 0 Answers

Admob not working i not find a solution 1 Answer

can i use admob ads with unity ads in Unity3d Game? 0 Answers

Admob interstitial ads 2 Answers

Xcode build error 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