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 /
  • Help Room /
avatar image
0
Question by dlscott1 · Jun 10, 2021 at 10:43 PM · loopsrepeating

Where do I place the while(true) in the following script without causing logic errors in run time?

Hello @Hellium! I wanted to thank you for helping me with this project. I appreciate your feedback and have learned a lot about how to use different approaches in using code. I received your message on the use of a while(true) loop and found that I didn't consider what would happen to other aspects of the code that didn't really need to repeat. When I ran the code with while(true) as you'd sent me I found that the count to string was no longer counting the appearances of the sphere or "Apple" prefab because the script was repeating only a count of 1 which makes sense. The word "Apple" being sent to randomOutcomeText.text would also always be the word apple without choosing another word at random, which again makes sense because the script is repeating the first choice due to the while(true) function. I thought that the while(true) would allow the script to choose a new word each time there was a loop but it makes the script not repeat for a different choice. Rather, it repeats the outcome of the first choice exactly and I didn't expect that. I tried separating the random word generator into a different script thinking that if I did that and set it to repeat it would help but I think the result is the same and it just chooses the same word. With that knowledge, I am unsure how to make the generator not repeat the outcome it chose before and instead repeat but be allowed to choose other words randomly. Is there a way to code for random word generation each time rather than a repeat of the first word choice?

What I would like is for the random word generator to choose one out of three words at random and if the word "apple" is chosen then the apple or sphere prefab appears and disappears only for the random word generator to randomly choose another word after a certain period of time. If the generator chooses a word that is not "apple" then nothing happens for a certain period of time. Like 16 seconds or something. After 16 seconds is up the random word generator should choose another word randomly again and so on. So whether or not the word apple is chosen, there should be a repeat but like I said, I am unsure how to get the script to repeat without repeating exactly the outcome before. :) How should I set the script (or scripts if I need to make other scripts) so as I can correct for this? I would open and respond to your comments through unity answers through my email but for some reason I am unable to reply back as the link to the page concerning the question is always broken for some reason and my question is removed from the search as well so I can never find it. Weird. Anywho, I found it super funny when I ran the game because I learned something new I wasn't expecting. Randomness is always funny! Again thank you for your time. I appreciate it and look forward to seeing your thoughts on the matter. Have a good evening!

Respectfully,

-Dlscott1

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

0 Replies

· Add your reply
  • Sort: 

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

160 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

Related Questions

How to use infinite loops or alternatively repeated tasks 1 Answer

Interacting with one objects activates other objects with similar scripts. 1 Answer

Yield return statement ends loop execution 0 Answers

Enumerator in for loop acting strangely 1 Answer

Looped bool with timed delay 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