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 /
avatar image
0
Question by singlearrowgames · Jun 24, 2020 at 05:13 AM · unity 5ads

Rewarded video ads for two different functions - Unity

I'm implementing reward based video ads in my game. There are two functions that provide the reward. One is a ReceiveLife() function where once the player dies, if they click on the revive button the game restarts and the score is set to score before the player dies instead of 0. The other function is ReceivePoints(), where if the player clicks on the add points button, they are rewarded with 100 extra points. Here are the functions in the game manager script:

 public class GameManager : MonoBehaviour
 {
   public Player player;
   public Transform startLocation;
 
   public GameObject startPanel, ingamePanel, gameoverPanel; 
 
   private bool gameHasStarted;
 
   public enum GameStates
   {
     Start,
     InGame,
     GameOver
   }
 
   public float playerScore = 0;
   static int savedScore;
   private int difficultyLevel = 1;
   private int maxDiffLevel = 10;
   private int scoreToNextLevel = 10;    
 
   private void Start()
   {
     SetupNewGame();
   }
 
   void Update()
   {
     if(playerScore >= scoreToNextLevel)
     {
         LevelUp();
     }
 
     if (player.dead == false && gameHasStarted)
     {
         playerScore += Time.deltaTime * difficultyLevel;           
     }       
         
     if (playerScore > PlayerPrefs.GetInt("HighScore", 0))
     {
         PlayerPrefs.SetInt("HighScore", (int)playerScore);
     }       
 }
 
  void LevelUp()
  {
     if (difficultyLevel == maxDiffLevel)
         return;
     scoreToNextLevel *= 2;
     difficultyLevel++;
 
  }
 
 public void SetupNewGame()
  {       
     playerScore = savedScore;
     savedScore = 0;      
     player.transform.position = startLocation.position;              
     UpdateUI(GameStates.Start);
  }
 
  public void StartNewGame()
  {
     player.dead = false;
     gameHasStarted = true;
     playerScore+=savedScore;
     UpdateUI(GameStates.InGame);
  }
 
 public void GameOver()
 {
     player.dead = true;
     gameHasStarted = false;        
     UpdateUI(GameStates.GameOver);        
 }
 
 void UpdateUI(GameStates gameState)
 {
     startPanel.SetActive(false);
     ingamePanel.SetActive(false);
     gameoverPanel.SetActive(false);
 
     if (gameState == GameStates.Start)
     {
         startPanel.SetActive(true);
     }
     if (gameState == GameStates.InGame)
     {
         ingamePanel.SetActive(true);
     }
     if (gameState == GameStates.GameOver)
     {
         gameoverPanel.SetActive(true);
     }
 }    
 
 public void ReceiveLife()
  {        
    savedScore = (int)playerScore;        
    SceneManager.LoadScene(1); 
  }
 
 public void ReceivePoints()
  {
    playerScore+=100;
    gameOverPanel.gameOverScoreText.text = "Score: " + 
                                            (int)playerScore).ToString();      
  }

Here is the part of unity ads manager script that provides the reward:

 public void OnUnityAdsDidFinish(string placementId, ShowResult showResult)
  {        
   if (showResult == ShowResult.Finished)
    {
     gameManager = GameObject.Find("GameManager").GetComponent<GameManager>();
     gameManager.ReceiveLife();
    }
 
   if (showResult == ShowResult.Finished)
    {
     gameManager = GameObject.Find("GameManager").GetComponent<GameManager>();
     gameManager.ReceivePoints();
    }       
   }

Once they watch the ad successfully, both the functions are being called. If the player clicks on the ReceiveLife(), he should only get one extra life and not the additional 100 points and vice-versa.

I'm not sure how to call each function separately. Do I have to create two separate admanagers in order to call these functions or is there a better method?

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
Best Answer

Answer by haizathaneefa · Jun 24, 2020 at 06:46 AM

Your reward conditions have the same kind. add a bool to differentiate between the two. have the bool to be true once the user pressed the button. example

   public void life()
     {
         life = true;
     }
 
     public void points()
     {
         points = true;
     }
 
     public void OnUnityAdsDidFinish(string placementId, ShowResult showResult)
     {
         if (showResult == ShowResult.Finished && life)
         {
             gameManager = GameObject.Find("GameManager").GetComponent<GameManager>();
             gameManager.ReceiveLife();
 
             life = false;
         }
 
         if (showResult == ShowResult.Finished && points)
         {
             gameManager = GameObject.Find("GameManager").GetComponent<GameManager>();
             gameManager.ReceivePoints();
 
             points = false;
         }
     }

Comment
Add comment · Show 2 · 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 singlearrowgames · Jun 24, 2020 at 08:41 AM 0
Share

@haizathaneefa , thanks a lot for the help....this is now working as expected....

avatar image haizathaneefa singlearrowgames · Jun 24, 2020 at 09:07 AM 0
Share

Glad I could help, and thank you for marking it as an answer. Happy coding!

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

232 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

Related Questions

video ads is not working 0 Answers

Show chartboost interstitial ads in specific window 0 Answers

Admob Interstitial Ads are not working in IOS, but it is working in Android 0 Answers

Admob rewarded videos not rewarding 1 Answer

Unity Ads Not working on my project 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