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 /
avatar image
0
Question by mpkostek · Dec 22, 2018 at 11:10 PM · coroutinewaitforseconds

WaitForSeconds causing function to return

I am calling WaitForSeconds in a coroutine like this:

    public override IEnumerator Activate()
    {
       if (!playerAttributes.isBurned)
       {
          spriteRenderer = playerAttributes.GetComponent<SpriteRenderer>();
 
          StartCoroutine(ActiveTimer());
 
          // Mark the player as burned so burn can't be applied again while
          // this instance of burn is active;
          playerAttributes.isBurned = true;
 
          // Make character red while they are burned
          playerAttributes.GetComponent<SpriteRenderer>().color = Color.red;
 
          while (isActive)
          {
             if (!playerAttributes.isDead)
             {
                playerAttributes.currentHealth -= damage;

                Debug.Log("Activate");
                yield return new WaitForSeconds(applyInterval);
                Debug.Log("TEST");
             }
             else
             {
                isActive = false;
             }
          }
 
          // White returns the sprite to its original colors
          spriteRenderer.color = Color.white;
 
          playerAttributes.isBurned = false;
       }
 
       yield return null;
    }

this function is called like this:

    public void AttemptToInflict()
    {
       // Inflict status if RNG decides it should happen
       if (percentageChanceToInflict >= Random.Range(0, 100))
       {
          StartCoroutine(Activate());
       }
    }

This is the contents of ActiveTimer(), statusDuration is 3f:

    protected IEnumerator ActiveTimer()
    {
       isActive = true;
 
       yield return new WaitForSeconds(statusDuration);
 
       isActive = false;
    }

"Activate" prints out every time, but "TEST" never prints. applyInterval is set to 1 and is of type float. Why is the function exiting on the WaitForSeconds() call?

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 Vega4Life · Dec 22, 2018 at 11:52 PM

It should work... Is there anything that is destroying or disabling that gameObject?

Comment
Add comment · Show 3 · 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 mpkostek · Dec 22, 2018 at 11:55 PM 0
Share

You know what... I think that might be it. This is in a Status class that is a component on a Bullet. The bullet gets destroyed when it makes contact with a player. I will go inspect this...

avatar image Vega4Life mpkostek · Dec 22, 2018 at 11:57 PM 0
Share

it's the only thing that makes sense. Code looks legit. :)

avatar image mpkostek Vega4Life · Dec 23, 2018 at 02:54 AM 0
Share

$$anonymous$$oving the Status script onto the player fixed the problem! Thank you!

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

104 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

Related Questions

SpeedBoost won't reset : Problem with either WaitForSeconds or Coroutine (Solved) 2 Answers

What's stopping 'WaitForSeconds' from working? 1 Answer

Is there a way to make WaitForSeconds ignore time.timescale? 1 Answer

How to start a Method after Coroutine has finished 3 Answers

How do I let the script wait a predetermined time? 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