Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 14 Next capture
2021 2022 2023
2 captures
12 Jun 22 - 14 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 surfuay · Mar 13, 2019 at 08:27 PM · coroutinesunityadspowerup

Activating all powerups at once is glitching my powerups

So I have an ad reward that activates powerups on my player. I'll post below but here's what's happening.

watch the ad activate powerups shield works ninja star does not after ONLY the power up video the ninja star stops working altogether. It doesn't crash the game but that specific powerup now remains in the "on" position AND does not throw the ninja stars despite be "on"

Player Code For the powerups;

public class Player : MonoBehaviour {

 public static Player ninja;
 public bool NinjaStarOn = false;
 public bool ShieldsOn = false;

 //not working fine
 public void NinjaStar()
 {
     NinjaStarOn = true;
     StartCoroutine(NinjaStarPowerDown());
 }

 //works fine
 public void NinjaShield()
 {
     ShieldsOn = true;
     _ninjaShield.SetActive(true);
     StartCoroutine(NinjaShieldPowerDown());
 }

}

And here is the Ad script that calls for the powerups to activate, both get activated yet, only the ninja shield functions properly public class ChestPowerAd : MonoBehaviour {

 public void ShowAd()
 {
     var options = new ShowOptions();
     options.resultCallback = HandleShowResult;

     Advertisement.Show(placementID, options);
 }

 void HandleShowResult(ShowResult result)
 {
     if (result == ShowResult.Finished)
     {
         Debug.Log("reward");
         Player.ninja.NinjaStar();
         Player.ninja.NinjaShield();
         UIManager.uIManager.rewardChestPowerButton.SetActive(false);
         UIManager.uIManager.rewardChestPowerVis = false;
         UIManager.uIManager.pauseMenuPanel.SetActive(true);
         UIManager.uIManager.pauseMenuVisible = true;
     }
 }

}

Comment
Add comment · Show 7
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 Taunchi · Mar 13, 2019 at 09:16 PM 0
Share

Are you returning in your coroutines?

avatar image surfuay Taunchi · Mar 14, 2019 at 01:14 AM 0
Share

i'm not sure what you mean by returning but in the coroutines there is an "off" function

//this is the power up that is working IEnumerator NinjaShieldPowerDown() {
yield return new WaitForSeconds(3); _ninjaShield.SetActive(false); ShieldsOn = false;
}

//this is the one that isn't working IEnumerator NinjaStarPowerDown() { yield return new WaitForSeconds(3); NinjaStarOn = false; }

when i get the power ups in normal gameplay they function perfectly.

avatar image surfuay Taunchi · Mar 14, 2019 at 01:15 AM 0
Share

oh, and the methods (Player.ninja.NinjaStar()/NinjaShield()) both call those coroutines in those methods

avatar image Taunchi surfuay · Mar 14, 2019 at 08:40 AM 0
Share

I meant calling in your coroutines to return some value or action. Have you tried nesting them? You could try running them in parallel in your Player script with something like this:

 private Coroutine shield, star;
 private IEnumerator powerDown;
 private bool down;
 
 void Start()
 {
     down = false;
     shield = StartCoroutine(NinjaShieldPowerDown());
     star = StartCoroutine(NinjaStarPowerDown());
     powerDown = PowerDown();
 }
 
 IEnumerator PowerDown()
 {
     down = true;
     yield return WaitForSeconds(3f):
     
     if(shield == null && ShieldsOn){ yield return shield;}
     if(star == null && NinjaStarOn){ yield return star;}
     
     down = false;
 }
     
 IEnumerator NinjaShieldPowerDown()
 {
     ninjaShield.SetActive(false);
     ShieldsOn = false;
 }
 
 IEnumerator NinjaStarPowerDown() 
 { 
     NinjaStarOn = false; 
 }

Then call powerDown in your NinjaStar and NinjaShield functions:

  public void NinjaStar()
  {
      NinjaStarOn = true;
      if(!down){StartCoroutine(powerDown);}
  }
 
  public void NinjaShield()
  {
      ShieldsOn = true;
      _ninjaShield.SetActive(true);
      if(!down){StartCoroutine(powerDown);}
  }
Show more comments

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

102 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

Related Questions

spawn a powerup in 2D platformer c# 1 Answer

ramdomised weapon pickup 1 Answer

So does StopAllCoroutines also CancelInvoke ? 1 Answer

Making an object blink and then move position 1 Answer

How do I script enemy AI movement using Coroutines? 1 Answer


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