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 /
  • Help Room /
avatar image
0
Question by Rembo4Fight · Mar 02, 2019 at 04:19 PM · gameobjectsystemforeachdialogueorder-of-execution

Dialogue System w/ Gameobject [ ] ?

Hello, I'm looking for a advice I want to use "Gameobject [ ]" to turn on and off text objects in order.alt text What method can be the answer? Example:

 foreach (GameObject mirror in mirrors) 
 {
 //turn on first mirror and turn on the next one
 }



12.jpg (32.2 kB)
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 Hellium · Mar 02, 2019 at 06:05 PM

 private IEnumerator EnableMirrors()
 {
     WaitForSeconds wait = new WaitForSeconds( 1 );
     int i = 0;
     mirrors[i].SetActive(true);
     for( ; i < mirrors.Length - 1 ; i++ )
     {
         yield return wait;
         mirrors[i].SetActive(false);
         mirrors[i+1].SetActive(true);
     }
      yield return wait;
      mirrors[i].SetActive(false);
 }

Comment
Add comment · Show 5 · 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 Rembo4Fight · Mar 02, 2019 at 10:50 PM 0
Share

Thanks! Okay, so I need to switch between lines by pressing the return button. The main thing, is that i need to change in not automatically, but from pressing the Return button, what must be changed or added? So the code looks like this for now:

 public GameObject[] lines;
 
     void Update()
     {
         if (Input.Get$$anonymous$$eyDown($$anonymous$$eyCode.Return))
         {
             StartCoroutine(Enable$$anonymous$$irrors());
         }
     }
 
     private IEnumerator Enable$$anonymous$$irrors()
     {
         WaitForSeconds wait = new WaitForSeconds(1);
         int i = 0;
         lines[i].SetActive(true);
         for (; i < lines.Length - 1; i++)
         {
             yield return wait;
             lines[i].SetActive(false);
             lines[i + 1].SetActive(true);
         }
         yield return wait;
         lines[i].SetActive(false);
     }

avatar image Hellium Rembo4Fight · Mar 03, 2019 at 07:43 AM 0
Share

If you want the gameObjects to be activated by the press of a button

Replace the following line

 WaitForSeconds wait = new WaitForSeconds( 1 );

By

 WaitUntil wait = new WaitUntil( () => Input.Get$$anonymous$$eyDown( $$anonymous$$eyCode.Return ) );

And add a Boolean to make sure the coroutine is not already running

  private bool dialogueDisplayed;
  void Update()
  {
      if (!dialogueDisplayed && Input.Get$$anonymous$$eyDown($$anonymous$$eyCode.Return))
      {
          StartCoroutine(Enable$$anonymous$$irrors());
      }
  }

  private IEnumerator Enable$$anonymous$$irrors()
  {
      dialogueDisplayed = true;
      WaitForSeconds wait = new WaitForSeconds(1);
      int i = 0;
      lines[i].SetActive(true);
      for (; i < lines.Length - 1; i++)
      {
          yield return wait;
          lines[i].SetActive(false);
          lines[i + 1].SetActive(true);
      }
      yield return wait;
      lines[i].SetActive(false);
      dialogueDisplayed = false;
  }
avatar image Rembo4Fight Hellium · Mar 03, 2019 at 08:04 AM 0
Share

Okay, hope I write it right, when I press return button now, it jumps very fast from 1st to second line, and third, goes very fast to and 4th line is active by pressing the return button just a second time etc., this is the main issue for now. And the last thing is that when the last line is on, lines must be closed by pressing the return button, how can this be achieved? Thanks for your help.

  public GameObject[] lines;
     private bool dialogueDisplayed;
 
     void Update()
     {
         if (!dialogueDisplayed && Input.Get$$anonymous$$eyDown($$anonymous$$eyCode.Return))
         {
             StartCoroutine(Enable$$anonymous$$irrors());
         }
     }
 
     private IEnumerator Enable$$anonymous$$irrors()
     {
         dialogueDisplayed = true;
         WaitUntil wait = new WaitUntil(() => Input.Get$$anonymous$$eyDown($$anonymous$$eyCode.Return));
         int i = 0;
         lines[i].SetActive(true);
         for (; i < lines.Length - 1; i++)
         {
             yield return wait;
             lines[i].SetActive(false);
             lines[i + 1].SetActive(true);
         }
         yield return wait;
         lines[i].SetActive(false);
         dialogueDisplayed = false;
     }
Show more comments

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

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

How to save and load complete gameobjects 0 Answers

How Do I Change UI Image Anchor Position To Hover Over GameObject? 1 Answer

Addressables' references - right object is there, but not! 1 Answer

using System.Drawing.DLL in standalone 1 Answer

Stucked in a infinite loop and don't know why 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