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 jollyapp34 · Nov 24, 2017 at 12:30 AM · scripting problem2d gameunity ads

How do you manage the amount of time Ads appear in your app?

I am new to using Unity Ads, so sorry if I am a bit confused. I am currently working on a 2d game. After every round you lose, an ad shows up after you die. Instead of this, I would like for ads to show up every two rounds out of five. I was wondering if someone knew the code to make this happen. Here is the current code with the ad codes implemented in it:


void GameOver() { GameState = GameState.GameOver; Advertisement.Show(); }


public void CheckGameOver(GameObject ball) { listBall.Remove(ball);

     if (listBall.Count == 0)
     {
         SoundManager.Instance.PlaySound(SoundManager.Instance.gameOver);
         gameOver = true;

         currentTargetPoint.SetActive(false);

         ParticleSystem particle = Instantiate(hitGold, currentTarget.transform.position, Quaternion.identity) as ParticleSystem;
         particle.startColor = currentTarget.gameObject.GetComponent<SpriteRenderer>().color;
         particle.Play();
         Destroy(particle.gameObject, 1f);
         Destroy(currentTarget.gameObject);
         Advertisement.Show ();

         GameOver();          
     }
 }


if (!gameOver) { SoundManager.Instance.PlaySound(SoundManager.Instance.gameOver); gameOver = true; for (int i = 0; i < listBall.Count; i++) { listBall[i].GetComponent().Exploring(); }

         currentTargetPoint.SetActive(false);

         ParticleSystem particle = Instantiate(hitGold, currentTarget.transform.position, Quaternion.identity) as ParticleSystem;
         particle.startColor = currentTarget.gameObject.GetComponent<SpriteRenderer>().color;
         particle.Play();
         Destroy(particle.gameObject, 1f);
         Destroy(currentTarget.gameObject);
 q`
         Advertisement.Show();
         GameOver();
     }


I would like to say thank you in advance. If you need any extra photos or code, just tell me and I will get it to you.

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 EDevJogos · Nov 24, 2017 at 01:41 AM

This should do it, it will show ads in 2 random rounds out of 5:

 //If you restart the round by reloading the Scene then make
 //this 2 variables static.
 int adsControl = 5;
 int roundShowAds = 0;
 
 //Make this test everytime you start a round
 if(adsControl < 5)
 {
     adsControl++;
 }
 else
 {
     adsControl = 0;
     roundShowAds = Random.Range(0, 5);
 }
 
 //Encapsule in this if your ShowAds call
 if(adsControl == roundShowAds || adsControl == (roundShowAds + 1) % 5)
 {
     //ShowAds();
 }
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 jollyapp34 · Nov 24, 2017 at 03:36 PM 0
Share

@Search Thank you for your response! I am still a bit confused. I placed both "int" line along with my other ones. I believe I messed up with one thing however. I replaced every "Advertisement.Show()" with:


//$$anonymous$$ake this test everytime you start a round if(adsControl < 5) { adsControl++; } else { adsControl = 0; roundShowAds = Random.Range(0, 5); }


That is probably incorrect. I also do not know where to place the lines:


//Encapsule in this if your ShowAds call if(adsControl == roundShowAds || adsControl == (roundShowAds + 1) % 5) { //ShowAds(); }


Sorry that I do not understand. Thank you for the help in advance.

avatar image EDevJogos jollyapp34 · Nov 24, 2017 at 04:57 PM 0
Share

Ok, what this code bellow does is count on which round you're, and randomize 2 values that will be the rounds where a ads will be displayed. This test has to be made everytime you start a new round and there only, i guess you have something like StartRound(); method.

 //$$anonymous$$ake this test everytime you start a round
  if(adsControl < 5)
  {
      adsControl++;
  }
  else
  {
      adsControl = 0;
      roundShowAds = Random.Range(0, 5);
  }

This other code, what it does is test if the current round is equal to one of the randomized values on the previous code, if so that means this round have to show a advertisement when gameover happens. So everytime on gameover you do this test to see if the current round will or not display a advertisement.

 if(adsControl == roundShowAds || adsControl == (roundShowAds + 1) % 5)
  {
      //Replace this comment with the call you use to display a advertisement.
     //I guess it is Advertisement.Show ();
 
  }
 

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

181 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

Related Questions

[Question] Unity C# Set a Player Class and refence issue 0 Answers

Identifying 3 GameObjects in contact with each other,Identifying and destroying 3 Game Objects with the same LayerName 0 Answers

Scripting errors in Unity Ads Import 1 Answer

Dialogue script shows previous sentences after a while 0 Answers

My character won't stop crouching, they dont stop crouchin 2 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