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 Dragon-Of-War · Sep 03, 2016 at 12:05 AM · coroutineyieldwaitforseconds

Script gets stuck on WaitForSeconds()

I have this script that creates a puddle for every 0.5 seconds. Though when the script gets to "yield return new WaitForSeconds()", it just stops right there. The rest of the FixedUpdate works but the CreatePuddle() is broken because of the WaitForSeconds(). Here's the script:

 using UnityEngine;
 using System.Collections;
 
 public class SlimeScript : EnemyScripts {
     //===========//
     //[VARIABLES]//
     //===========//
 
     //Public Variables
     public GameObject puddle;            //Puddle prefab
     public float delay;                    //Delay between puddle creations
 
     //Private variables
     bool canCreatePuddle = true;        //Can the script create another puddle?
 
     //===========//
     //[FUNCTIONS]//
     //===========//
 
     //Creates a puddle
     IEnumerator CreatePuddle(){
         canCreatePuddle = false;
         //Instantiate a puddle and sets the values
         Vector3 pos = new Vector3 (transform.position.x,transform.position.y,transform.position.z);
         GameObject newPuddle = Instantiate (puddle,pos,Quaternion.Euler(Vector3.zero)) as GameObject;
         newPuddle.transform.parent = transform.parent;
         newPuddle.GetComponent<DamageDealer> ().damage = damage;
         newPuddle.GetComponent<DamageDealer> ().friendly = false;
         //Delay
         print ("Created puddle");
         yield return new WaitForSeconds (0f);
         print ("Create new puddle");
         //Allow the script create another puddle
         canCreatePuddle = true;
     }
 
     public override void FixedUpdate(){
         base.FixedUpdate (); //Does everything that's in the base's FixedUpdate()
         //Create's a puddle
         if (canCreatePuddle)
             StartCoroutine (CreatePuddle());
         print ("Done");
     }
 }
 

UPDATE: https://youtu.be/uJURvk7rWB4. I'm still with the issue. I removed the enemy from the level and it worked.

Comment
Add comment · Show 5
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 Whiteleaf · Sep 03, 2016 at 12:17 AM 0
Share

Try putting in "0.0001f" ins$$anonymous$$d of 0f. That might be the issue.

If it prints, "Created Puddle", then the co routine is being called. If it prints, "Create new puddle", then it gets past the co routine. Otherwise, it's that causing it.

avatar image doublemax · Sep 03, 2016 at 12:17 AM 0
Share
 yield return new WaitForSeconds (0f);

Did you try WaitForSeconds with a value > 0? $$anonymous$$aybe it's bugged and waits forever if you pass 0.

avatar image Dragon-Of-War · Sep 03, 2016 at 12:20 AM 0
Share

Yes, i did. I also forgot to mention that it didn't print "Created new puddle".

avatar image doublemax Dragon-Of-War · Sep 03, 2016 at 12:28 AM 0
Share

Did you try starting the Coroutine from Update()? $$anonymous$$aybe the FixedUpdate() is the problem.

avatar image Dragon-Of-War · Sep 03, 2016 at 12:29 AM 0
Share

Ok so i tested something and it worked, though i had to remove the enemy out of the level. I will be making a video showing it.

1 Reply

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

Answer by Dragon-Of-War · Sep 03, 2016 at 12:43 AM

The problem wasn't with the script. I guess the rooms switched deactivated in a way the the script glitched.

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

58 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

Related Questions

Another yield not working problem 2 Answers

Is there any way to stop WaitForSeconds() ? 1 Answer

Understanding yield inside a for or a while loop 2 Answers

Waypoint / Yield help 1 Answer

lock a target after a few seconds 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