Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 14 Next capture
2021 2022 2023
2 captures
13 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 Ryujose · Oct 10, 2014 at 03:56 PM · uibuttoncanvascoroutine

Problem with coroutine.

Hello community.

I'm doing use of canvas UI Button for this.

On the inspector I call the "void StartGame" and it Works but the only thing is the Coroutine that it doesn't load 100% well.

The debug.log show me the stat "BeforWaiting2Seconds" But "AfterWaiting2Seconds" definitely won't show.

 using UnityEngine;
 using System.Collections;
 
 
 public class InicioDelJuego : MonoBehaviour {
     
     public AudioClip buttonStart;
 
     public void MyButtonLoad ()
     {
         StartCoroutine (StartButton());
     }
 
     IEnumerator StartButton ()
     {
             Debug.Log ("BeforWaiting2Seconds");
             yield return new WaitForSeconds (2);
             Debug.Log ("AfterWaiting2Seconds");
 
     }
 
     public void StartGame()
     {
         MyButtonLoad ();
         AudioSource.PlayClipAtPoint(buttonStart, new Vector3(0, 0, 0));
         Application.LoadLevel("EnterLevel1Scene");
     }

Any help will be appreciate, I'm sure is a foolishness but I can see what is it.

Regards.

Comment
Add comment · Show 1
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 Ryujose · Oct 10, 2014 at 05:55 PM 0
Share

I've tried to do a for with a break but it doesn't work it do the same.

 using UnityEngine;
 using System.Collections;
 
 
 public class InicioDelJuego : $$anonymous$$onoBehaviour {
     
     public AudioClip buttonStart;
 
     private int seconds = 2;
     private int secondsStart;
 
     public void $$anonymous$$yButtonLoad ()
     {
         StartCoroutine (StartButton());
     }
 
     IEnumerator StartButton ()
     {
             
             Debug.Log ("BeforWaiting2Seconds");
             yield return new WaitForSeconds (seconds);
             Debug.Log ("AfterWaiting2Seconds");
         {
             for ( secondsStart = 0; secondsStart < seconds; secondsStart++ )
                 break;
 
     }
     }
 
     public void StartGame()
     {
         $$anonymous$$yButtonLoad ();
         AudioSource.PlayClipAtPoint(buttonStart, new Vector3(0, 0, 0));
         Application.LoadLevel("EnterLevel1Scene");
     }

2 Replies

· Add your reply
  • Sort: 
avatar image
0
Best Answer

Answer by Ryujose · Oct 10, 2014 at 06:39 PM

I'll put my code here for the one's having the same problema as me. With this it Works. Thanks for yout help Zentiu.

 using UnityEngine;
 using System.Collections;
 
 
 public class InicioDelJuego : MonoBehaviour {
     
     public AudioClip buttonStart;
 
     private float seconds = 0.6f;
 
 
 
     public void MyButtonLoad ()
     {
         StartCoroutine (StartButton());
 
     }
 
     IEnumerator StartButton ()
     {
             
             Debug.Log ("BeforWaiting0.6Seconds");
              AudioSource.PlayClipAtPoint(buttonStart, new Vector3(0, 0, 0));
             yield return new WaitForSeconds (seconds);
             Debug.Log ("AfterWaiting0.6Seconds");
             Application.LoadLevel("EnterLevel1Scene");
         {
 
     }
     }
 
 
 
     public void StartGame()
     {
         MyButtonLoad ();
 
     }
Comment
Add comment · 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
2

Answer by HarshadK · Oct 10, 2014 at 06:48 PM

I guess I'm late for the party since question is already answered but I'll post the reason behind the behavior.

You are calling MyButtonLoad from your StartGame. And MyButtonLoad calls coroutine and everything before yield executes from it. So after the MyButtonLoad is called it moves to next line in StartGame and loads a scene where your coroutine stops hence nothing after yield executes. If you comment Application.LoadLevel statement you can see coroutine will execute fully.

Comment
Add comment · 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

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

30 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

Related Questions

Multiple Cars not working 1 Answer

Strange UI Button hover offset when using Worldspace Canvas in VR 4 Answers

UI elements are not getting affected by lighting 0 Answers

UI 4.6 canvas button, how to make it invisible on gameplay and how to make it visible when player is dead? 3 Answers

My UI buttons work fine in editor but when I exported the game on Android, only some of them works. 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