Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 13 Next capture
2021 2022 2023
1 capture
13 Jun 22 - 13 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 ChrisSch · Jul 14, 2013 at 09:57 PM · yieldwaitforsecondsmine

Yield refuses to work. Js

Can someone help me, yield won’t work for me, this is the second project it won’t work in, and I’ve tried reinstalling too as well as installing previous versions of Unity cause I do not see what I'm doing wrong.

 function Lose()
 {
 print(“before yield”);
 yield (WaitForSeconds(2));
 print(“after yield”);
 Time.timeScale = 0;
 guiMode = “Lose”;
 }

“before yield” prints out, but “after yield” never shows up and neither does anything after it. However if I remove the yield line all together everything works except the explosion doesn’t get to show that way…

I tried all variations of yield I can think off and none work.

I tried like the one in the tutorial video (Mine Lander UnityCookie) and:

 yield WaitForSeconds(2);

and

 yield (WaitForSeconds(2.0));

and

 yield WaitForSeconds(2.0);

but none work, only “before yield" prints out and no menu pops up and time doesnt freeze. And like I mentioned, it didn't work in another project either.

Any ideas, or alternative ways of waiting a couple sec?

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

2 Replies

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

Answer by ChrisSch · Jul 15, 2013 at 04:59 AM

Ok solved it.

Since I had another object calling the function Lose, which I didn't mention cause I didn't think it was important, and the object calling it got destroyed after calling it, the Lose function stopped executing all together. I thought I just have to call it before destroying the object and it would work fine, like it does in the tut, but it doesn't. xD

Anyway in case someone needs it, I solved it by adding another function, LoseCaller onto the GUI Object that doesn't get destroyed, as a relay even tho that one never gets destroyed in any case. Guess it kind of makes sense now why it wouldn't work... Oh well. xD

Ship Object:

 var GUI : InGameGUI;
 
 function Start ()
 {
     GUI = GameObject.FindWithTag("GUI").GetComponent(InGameGUI);
 }
 
 function Explode()
 {
     var randomNumber : int;
     randomNumber = Random.Range(0,shipExplossions.length);
     Instantiate(shipExplossions[randomNumber], transform.position,transform.rotation);
     GUI.LoseCaller();
     Destroy(gameObject);
 }

GUI Object:

 function Lose()
 {    
 
     print("before yield");
     yield (WaitForSeconds(2));
     print("after yield");
     Time.timeScale = 0;
     guiMode = "Lose";
 }
 
 function LoseCaller()
 {
     Lose();
 }
Comment
Add comment · Show 4 · 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 ArmarageX · Aug 02, 2013 at 08:15 AM 1
Share

just want to confirm this worked for me! Thanks for finding out this! Although this should not be normal.......(or hasnt been before..) Is this the new standard..... or a bug?!?!

avatar image ChrisSch · Aug 02, 2013 at 06:00 PM 0
Share

Its a new "we're still noobs and don't know exactly what we're doing so somewhere else in our script might be the problem" xD

Or its a bug, I really don't know cause I followed the tutorial to the letter and it didn't work but when I tried a simpler example it did, so no idea if bug or new standard or both. xD

avatar image ArmarageX · Aug 04, 2013 at 12:00 AM 0
Share

my code has always worked for me... until i recently upgraded to Unity 4.2.... Now i gotta relay....>.<

avatar image ChrisSch · Aug 04, 2013 at 07:24 AM 0
Share

I guess its a bug then. xD $$anonymous$$y Unity works better as of 4.2, and I'm loving the one directional light with shadows. xD Are you doing this tutorial too or something else?

avatar image
0

Answer by Eric5h5 · Jul 14, 2013 at 10:45 PM

Change timeScale to 1.0 before doing the yield.

Comment
Add comment · Show 1 · 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 ChrisSch · Jul 15, 2013 at 03:36 AM 0
Share

It was 1 since the explosion happens, but even so I changed it before yield again, and nothing new happens. It never passes the yield line.

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

17 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

Related Questions

Why Is yield return new WaitForSeconds() not working 2 Answers

Definition of Script.function() depends on Script.function()... 3 Answers

Script gets stuck on WaitForSeconds() 1 Answer

Wow, my enemies are pretty strong! 1 Answer

yield WaitForSeconds waits for too long. 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