Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 13 Next capture
2021 2022 2023
1 capture
13 Jun 22 - 13 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 kairgozhins · Jul 11, 2020 at 12:44 PM · scripting problemscript.unity adsscriptingproblem

How to use method from one script in the other one? UnityAd script.,How to connect method from other script? After Unity Ad shown giving second chance.

Hello there! I'm struggling with connecting Unity Ads to the button and letting player have second chance (Continue playing) after ad is shown.I have 2 scripts. One has everything related to Menu and UI's, the other is Ad itself. After ad is shown, I want to use the game method StartGame() from 1st script in 2nd script with the ad (at // Reward the user for watching the ad to completion.) That's script 1

 using System.Collections;
 using System.Collections.Generic;
 using UnityEngine;
 using UnityEngine.SceneManagement;
 using UnityEngine.Advertisements;
 using UnityEngine.UI;
 
 public class App_Initialize : MonoBehaviour{
 
         public GameObject inMenuUI;
         public GameObject inGameUI;
         public GameObject gameOverUI;
         public GameObject adButton;
         public GameObject player;
         private bool hasGameStarted = false;
         private bool hasSeenRewardedAd = false;
 
 
     void Awake() {
         Application.targetFrameRate = 60;
                 }    
 
     // Start is called before the first frame update
     void Start()
     {
         player.GetComponent<Rigidbody>().constraints = RigidbodyConstraints.FreezePosition;
     inMenuUI.gameObject.SetActive(true);
     inGameUI.gameObject.SetActive(false);
     gameOverUI.gameObject.SetActive(false);
         
     }
 
     public void PlayButton() {
 
     if (hasGameStarted == true) {        
                         StartCoroutine(StartGame(1.0f));
                     }
     else {
     StartCoroutine(StartGame(0.0f));
 }
 
                 }
 
     public void PauseGame() {
 
          player.GetComponent<Rigidbody>().constraints = RigidbodyConstraints.FreezePosition;
     hasGameStarted = true;
         inMenuUI.gameObject.SetActive(true);
         inGameUI.gameObject.SetActive(false);
         gameOverUI.gameObject.SetActive(false);
     
 
             }
 
 
     public void GameOver() {
         player.GetComponent<Rigidbody>().constraints = RigidbodyConstraints.FreezePosition;
         hasGameStarted = true;
         inMenuUI.gameObject.SetActive(false);
         inGameUI.gameObject.SetActive(false);
         gameOverUI.gameObject.SetActive(true);
     if (hasSeenRewardedAd == true) {
         adButton.GetComponent<Image>().color = new Color (1, 1, 1, 0.5f);  
         adButton.GetComponent<Button>().enabled = false;
     }
 }
 
     public void RestartGame() => SceneManager.LoadScene(0); //loads 0 index scene the one in building settings or whatever
 
     
 
     public IEnumerator StartGame(float waitTime) {
         
         inMenuUI.gameObject.SetActive(false);
         inGameUI.gameObject.SetActive(true);
         gameOverUI.gameObject.SetActive(false);
         yield return new WaitForSeconds(waitTime);
         player.GetComponent<Rigidbody>().constraints = RigidbodyConstraints.None;
         player.GetComponent<Rigidbody>().constraints = RigidbodyConstraints.FreezePositionY;
 
 
                     }
 }
 
 

And this is the second one.

 using UnityEngine;
 using UnityEngine.UI;
 using UnityEngine.Advertisements;
 using System.Collections;
 using System.Collections.Generic;
 
 [RequireComponent (typeof (Button))]
 public class Ad : MonoBehaviour, IUnityAdsListener {
 
     #if UNITY_IOS
     private string gameId = "3706758";
     #elif UNITY_ANDROID
     private string gameId = "3706759";
     #endif
 
     Button myButton;
     public string myPlacementId = "rewardedVideo";
    
 
 
     void Start () {
         myButton = GetComponent <Button> ();
 
         // Set interactivity to be dependent on the Placement’s status:
         myButton.interactable = Advertisement.IsReady (myPlacementId);
 
         // Map the ShowRewardedVideo function to the button’s click listener:
         if (myButton) myButton.onClick.AddListener (ShowRewardedVideo);
 
         // Initialize the Ads listener and service:
         Advertisement.AddListener (this);
         Advertisement.Initialize (gameId, true);
     }
 
     // Implement a function for showing a rewarded video ad:
     void ShowRewardedVideo () {
         Advertisement.Show (myPlacementId);
     }
 
     // Implement IUnityAdsListener interface methods:
     public void OnUnityAdsReady (string placementId) {
         // If the ready Placement is rewarded, activate the button:
         if (placementId == myPlacementId) {
             myButton.interactable = true;
         }
     }
 
     public void OnUnityAdsDidFinish (string placementId, ShowResult showResult) {
         // Define conditional logic for each ad completion status:
         if (showResult == ShowResult.Finished) {
       
       
 
             // Reward the user for watching the ad to completion.
         } else if (showResult == ShowResult.Skipped) {
             // Do not reward the user for skipping the ad.
         } else if (showResult == ShowResult.Failed) {
             Debug.LogWarning ("Failed");
         }
     }
 
     public void OnUnityAdsDidError (string message) {
         // Log the error.
     }
 
     public void OnUnityAdsDidStart (string placementId) {
         // Optional actions to take when the end-users triggers an ad.
     }
 
     
 
 
 
 
 }
 

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

0 Replies

· Add your reply
  • Sort: 

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

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

UnityCar - Controlling Speed with a duration? 2 Answers

Help with [SerializeField] in a script! 1 Answer

How can I get all cameras enabled true false states ? 0 Answers

Set public gameobject by raycast hit target 1 Answer

Problem with the cloning object :( 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