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 naqvir · Mar 27, 2012 at 12:04 AM · gameobjectcomponentloopwhile

Breaking out of a loop

hi peeps,

Im very confused as to why this do while loop doesnt work. I always get stuck in an infinite loop. It works if i only have one condition but as soon as i insert multiple conditions it doesnt leave the loop.

  do {        
      ran = Random.Range(0,names.length);
 
      var ran2:int = Random.Range(0,objectComponants[names[ran]].length); // the length counts the componants array within the hashtable
      
      var chosenComponent:Component = objectComponants[names[ran]][ran2];
  }
  while ((typeof(chosenComponent)!= Transform) || (typeof(chosenComponent)!= ParticleSystem));



Its waiting to find if the chosen component is either a transform or particle system then it should break.

Thanks in advance

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 naqvir · Mar 27, 2012 at 12:09 AM

I worked out that instead of || you need to use &&. But i have no idea why? I would have thought || is more appropriate as it should break when either of the two types are found. Im afraid whilst && fixes the problem, i dont understand why.

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
1

Answer by IndieScapeGames · Mar 27, 2012 at 12:19 AM

If you want it to break if either one is true, than you do need to use ||.

If you're using &&, that means both have to be true to continue.

You're also using not logic, I don't know if you understand that or not.

When you include !=, that means not equal to. So your

while is saying while the chosenComponent is NOT a Transform, OR the chosenComponent is NOT a Particle System.. do this..

To change the paragraph with your AND (&&) statement, it's saying this:

 While the chosenComponent is NOT a Transform AND while the chosenComponent is NOT a Particle, do this..
Comment
Add comment · Show 1 · 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 naqvir · Mar 27, 2012 at 01:02 AM 0
Share

thanks , makes more sense now

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

4 People are following this question.

avatar image avatar image avatar image avatar image

Related Questions

Can I move a component from one GameObject to another in script? 1 Answer

Can I play multiple AudioSources from one gameobject? 8 Answers

While loop questions 3 Answers

How to mimic Unity's Components based System 1 Answer

How to Check if a component Exists on a Gameobject. 3 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