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 /
This post has been wikified, any user with enough reputation can edit it.
avatar image
0
Question by lampshade · Jul 10, 2010 at 09:47 PM · particleswaitforsecondsienumerator

Instantiate Particles, WaitForSeconds and continue

Hi,

I have been working with trying to achieve the following:

1) Player Steps onto a trigger
2) Player Presses a key while on trigger to Instantiate particles
3) Particles instantiate
4) Start to WaitForSeconds(3.5f)
5) End of 3.5 seconds->Fade Particles out by code (ParticleAnimator)
6) WaitForSeconds(3.5f)
7) End of 3.5 seconds->Reinstantiate Particles (may be unecessary)

Steps 4 - 7 should continue doing so until the Player moves i.e. (Mathf.Abs(PlayerMoveScript.MoveForward) > 0)) even if Player remains on trigger.

I can start by showing the code for when the player presses a key to instantiate particles (assuming everything is declared):

OnTriggerStay(Collider other) { void InstantiateParticles() { if (Input.GetKeyDown("space") && PlayerMoveScript.MoveForward == 0) { if (RedParticles != null && theRedParticles == null) { Debug.Log("Preparing to instantiate"); theRedParticles = (GameObject) Instantiate(RedParticles, transform.position, Quaternion.identity); newRedParticles = (GameObject) RedParticles;

             StartCoroutine(FadeParticles());
         }
     }
 }

} private IEnumerator FadeParticles() { yield return StartCoroutine(Wait())

         if (theRedParticles != null)
         { 

             holder = new Color[5];
             holder = theRedParticles.GetComponent<ParticleAnimator>( ).colorAnimation;

             for (int x=0; x<5; x++) 
                 holder[x].a -= 0.02f;

             theRedParticles.GetComponent<ParticleAnimator>( ).colorAnimation = holder;

             yield return StartCoroutine(Wait());
             Debug.Log("Done Waiting Again..");
             // try to use another prefab with the same qualities.
             theRedParticles = newRedParticles;
         }

     yield return 0;
 }



private IEnumerator Wait() { yield return new WaitForSeconds(3.5f); }

Revised code Result: The code does not wait for 3.5 seconds, for some reason.

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

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

Answer by Daniel 6 · Jul 10, 2010 at 10:12 PM

Just quickly looking at your code I noticed one issue. You have a static IEnumerator method and that doesn't work. Methods with yield commands can not be static.

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 lampshade · Jul 11, 2010 at 01:48 AM 0
Share

I appreciate your help, but it does not appear to be waiting for 3.5 seconds (even if I do a * Time.deltaTime)

avatar image lampshade · Jul 11, 2010 at 02:00 AM 0
Share

I forgot yeild return StartCoroutine(FadeParticles()). And the particles happen to not fade as I intended. Any suggetions for that? Or would I need to make another post?

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

No one has followed this question yet.

Related Questions

WaitForSeconds does not work 0 Answers

yield return waitforseconds not waiting? 3 Answers

Respawn Time 1 Answer

WaitForSeconds in virtual void. having trouble understanding IEnumerator 1 Answer

Pause script until animation is finished. 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