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 LordZephyr · Jan 29, 2014 at 08:26 PM · yieldstopwaitstops

Why is my "yield" statement stopping my script?

Hi, I can't seem to figure out what is wrong with my script. I am creating a roller ball game and I want the ball to disappear when it triggers a hit on the wall. Everything works great separately but when I add a line to get rid of the camera follow script, the script stops at my "yield" command. If I remark out the "yield" command, it works fine but there isn't enough time to complete the explosion and sound before it loads the "reset" level. Can someone please take a look at my script and tell me why it stops at "yield"? Thank you so much!!! Tom

 #pragma strict
 
 var explosionEnd : Transform;
 
 function Start ()
 {
 
 }
 
 function Update ()
 {
 
 }
 
 
 function OnTriggerEnter (myTrigger : Collider)
 {
     if(myTrigger.gameObject.name == "WallSide")
     {
         
         //Create explosion wherer the ball is (not done yet)
         Instantiate (explosionEnd);
         
         Debug.Log ("I hit something.");
         
         //Make the RollerBall disapear
         Destroy (gameObject.Find("Player"));
         
         //Get rid of the camera script so it stops trying to find the RollerBall
         Component.Destroy(Camera.main.gameObject.GetComponent("CameraFollow"));
         
         Debug.Log ("This is the second message.");
 
         //Wait for the explosion and sound to complete
         yield WaitForSeconds(2);
         
         //Load the start over menu level
         Application.LoadLevel ("Level 7 Reset");
         
         Debug.Log ("This is a third message.");
     }
     
 }
Comment
Add comment · Show 2
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 Invertex · Jan 29, 2014 at 08:49 PM 0
Share

shouldn't it be "yield return WaitForSeconds(2);"?

avatar image Eric5h5 · Jan 29, 2014 at 09:19 PM 0
Share

No, that's only for C# (except it would be "yield return new WaitForSeconds").

1 Reply

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

Answer by Eric5h5 · Jan 29, 2014 at 09:22 PM

You're destroying the object, so the script doesn't exist anymore. The only reason it would work without yield is because destroyed objects aren't removed until the end of the frame.

Comment
Add comment · Show 2 · 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 LordZephyr · Jan 29, 2014 at 10:14 PM 0
Share

Oh my goodness!!! I was staring at that script all day and kept thinking to myself that it's a simple script. Why can't I figure it out???

I feel silly but it goes to show you that you need to get away from your work once in a while.

Thanks so much, @Eric5h5!!! I really appreciate your help! $$anonymous$$

avatar image Eric5h5 · Jan 30, 2014 at 12:26 AM 0
Share

it goes to show you that you need to get away from your work once in a while.

All too true. Applies to other stuff like writing docs too...I'll write something that seems fine only to discover the next day that it was actually gibberish.

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

20 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

Related Questions

how would i cause the function to wait until it stops to function again? 1 Answer

Exit playmode at runtime using code 1 Answer

The waitforseconds does not run? 1 Answer

Best way to wait for event inside Coroutine? 3 Answers

Stopping One Function From Another 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