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 Mrroundtree22 · Feb 23, 2021 at 10:48 AM · loopforeachdebug.log

More loop problems

private bool[] loopBool = 3;

Script 1 public void ActivateScript1(){

 int i = 0;
 
 if(!loopBool[i]){
 Script2.ActivateScript2();
 }
 
  for (; i < max; i++)
              {
                    loopBool[i] = true;
              }
  }
  
      Script 2
  
      public void ActivateScript2(){
      foreach (var item in collection)
              {
                   Debug.Log("A");
              }
  }
 

ActivateScript1 is activated via a button. I want it so that if I press the button the debug message appears. Then I want that slot in the boolArray to turn true. And it should do this max 3 times since that is the size of the bool array.

Unfortunately as is now the first slot turn true and nothing happens after I press the button again. I know this might seem complicated ask for info if you are confused.

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
0

Answer by GeroNL · Feb 23, 2021 at 11:46 AM

hello, what do you mean about "nothing happens after I press the button again"?


Is the problem doesn't appear again? if it is because after slot [0] (cause 'i' is zero ) going to be true after that that it's never back to false, you must set it false to make it work again.


or the problem is doesn't make slot [1] and [2] true? if it's that you mean, that because you are never set "i" to slot that you want to be changed.


Hope it help.

Comment
Add comment · Show 6 · 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 Mrroundtree22 · Feb 23, 2021 at 12:34 PM 0
Share

Exactly. The first thing is what happens. I know that. I don't know how to solve it. If [0] = true then I want it to go the next [1]. It only stops when all the slots in the bool array is true.

Now it just checks if [i] is true which it is once [0] = true.

avatar image GeroNL Mrroundtree22 · Feb 23, 2021 at 01:15 PM 0
Share

if you want to all true then all false, you can do like this:

 // set it after iteration (for)
 if(i == loopBool.length-1)
 {
     i = 0;    
     while(loopBool[loopBool.length-1])
     {
         loopBool[i] = false;
         i++;
     }
     i = 0;
 }

avatar image Mrroundtree22 GeroNL · Feb 23, 2021 at 01:37 PM 0
Share

No, I want it so that when I press the button [0] = true. When I press the button again then [1] = true and so on.

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

113 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

Related Questions

How do I create a variable for each GameObject that I added to an array by using a loop? 2 Answers

foreach loop stops at first item 1 Answer

Not able to make a foreach loop 2 Answers

Array Element in Foreach loop 1 Answer

How to have a loop run itself again if returned value is a known exception, with a new return value. 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