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 Zhavina · Jul 14, 2017 at 05:44 PM · coroutinedisappearplatformsappearforloop

Make a platform disappear after the next one appear

Hi everybody !

I pretty nex to Unity and c# and I'm making a 3D platform game in which I would implement the same mechanic than in HeatMan stage from MegaMan 2. Make platforms disappear as the next appear.

I tried to make my plateforms appear while every other disappear, but it doesn't work correctly.

Here's what I've tried so far :

 void Update ()
 {
     StartCoroutine(MegaManTrap());
 }

 IEnumerator MegaManTrap()
 {
     for (int i = 0 ; i < pf.Length ; i++)
     {
         if (pf[i].activeInHierarchy == false)
         {
             pf[i].SetActive(true);
         }

         yield return new WaitForSeconds(Pop);

         for (int v = 0 ; v < pf.Length ; v++)
         {
             if (v != i)
             {
                 if (pf[i].activeInHierarchy == true)
                 {
                     pf[i].SetActive(false);
                 }
             }
         }
         yield return new WaitForSeconds(Depop);
     }
 }

I don't find the right way to do this, is it possible to have some help plz =) ?

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
0
Best Answer

Answer by Jwizard93 · Jul 14, 2017 at 06:16 PM

I don't know yet if the coroutine is written correctly in terms of the logic but you are starting a coroutine every frame so that is surely one problem that must be fixed. See what happens if you start the coroutine once in Start() function instead of Update()

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
0

Answer by Zhavina · Jul 14, 2017 at 06:28 PM

Oh, it worked pretty well, every platforms appear and disappear as expected but just once, how can I make the coroutine loop while I play in the start function ?

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 Zhavina · Jul 14, 2017 at 06:45 PM 0
Share

Ok I solved my problem ! I just reset the variables when all the platforms appeared one time.

I don't know if my code is written correctly but it work as I wanted.

 IEnumerator $$anonymous$$ega$$anonymous$$anTrap()
 {
     for (int i = 0 ; i < pf.Length ; i++)
     {
         if (pf[i].activeInHierarchy == false)
         {
             pf[i].SetActive(true);
             totalPfActivated++;
         }

         yield return new WaitForSeconds(Pop);

         for (int v = 0 ; v < pf.Length ; v++)
         {
             if (v != i)
             {
                 if (pf[i].activeInHierarchy == true)
                 {
                     pf[i].SetActive(false);
                 }
             }
         }

         if (totalPfActivated == pf.Length)
         {
             i = -1;
             totalPfActivated = 0;
         }

         Debug.Log(totalPfActivated);
     }
 }

Thanks you @Jwizard93

avatar image Jwizard93 Zhavina · Jul 14, 2017 at 09:30 PM 0
Share

Looks like a fine solution to me. Glad I could help.

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

72 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 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

Realize toroidal movement 2 Answers

Load Children One at a Time 1 Answer

Make enemy appear in front of player and then disappear at random times 2 Answers

Object appear and disappear on command 1 Answer

Getting For Loops to work in a Coroutine 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