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 /
  • Help Room /
This question was closed Apr 25, 2018 at 11:53 PM by S_jay1 for the following reason:

The question is answered, right answer was accepted

avatar image
0
Question by S_jay1 · Jan 29, 2018 at 10:53 PM · canvascoroutineienumerator

Why is my coroutine not working?

I'm trying to set a canvas (it's disabled when the game starts) to true after a player dies, but like 5 seconds after the player has died. I'm trying to use a coroutine and an Ienumerator but it keeps the canvas disabled. This is what I have:

     IEnumerator endSceneActive()
     {
         end.transform.position = new Vector3(0,1, zPosofDeadPlayer + 6);
         yield return new WaitForSeconds(5);
         end.SetActive(true);
     }
 
     void PlayerisDead()
 
 {
     StartCoroutine(endSceneActive());
 }
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

  • Sort: 
avatar image
1
Best Answer

Answer by victorbisaev · Jan 31, 2018 at 12:38 AM

You can try to do the following:

  1. Check if the Canvas is enabled in Hierarchy panel in editor after 5 seconds.

  2. Add "Debug.Log" before and after "yield return new WaitForSeconds(5);" and check if the messages appear in Console panel.

  3. Add "Debug.Log" just prior to "StartCoroutine(endSceneActive());" and check Console message

The code you provided looks good so may be the problem is not in coroutine.

Comment
Add comment · Show 5 · 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 S_jay1 · Feb 01, 2018 at 11:06 PM 0
Share

I can't add Debug.Log because of this error "Only assignment, call, increment, decrement, await, and new object expressions can be used as a statement"

avatar image victorbisaev S_jay1 · Feb 01, 2018 at 11:38 PM 0
Share

Try this:

 IEnumerator endSceneActive()
 {
     Debug.Log("endSceneActive before yield");
     m_chunks.transform.position = new Vector3(0, 1, 3 + 6);
     yield return new WaitForSeconds(5);
     Debug.Log("endSceneActive after yield");
     m_chunks.SetActive(true);
 }
 
 void PlayerisDead()
 {
     Debug.Log("PlayerisDead before StartCoroutine");
     StartCoroutine(endSceneActive());
 }

If you see all the debug messages in your Log panel then check zPosofDeadPlayer value - maybe it is absolutely wrong.

Also please notice that end.transform.position set absolute world position. Check if the Canvas is in the camera frustum when it is at this world position.

avatar image S_jay1 victorbisaev · Feb 02, 2018 at 02:57 PM 0
Share

I removed the zPosofDeadPlayer and I changed it so there would be a camera being enabled and disabled, but it still doesn't work. The log doesn't show anything. It seems like the IEnumerator is just not activating at all, the function doesn't seem to be going through.

Edit: If the player dies, would the IEnumerator still start if the PlayerisDead function is called beforehand?

This is how I am calling the function: void OnTriggerEnter (Collider other) { if (other.gameObject.tag == "Floor") { return; }

         if (other.gameObject.tag != "Floor") {
             PlayerisDead();
             Destroy (gameObject);
 
     
         }
 
     }
Show more comments

Follow this Question

Answers Answers and Comments

132 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

Related Questions

Unity - Lines after yield not getting executed 0 Answers

Why is my coroutine not working? 0 Answers

Add points every five seconds 1 Answer

Changing order in layers at runtime with a coroutine 0 Answers

Coroutine not working on android build 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