Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 14 Next capture
2021 2022 2023
2 captures
13 Jun 22 - 14 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 SwathedOrange · May 03 at 06:48 PM · listrandomlists

Return question’s answer at the determined index

if I have a list {1, 1, 2, 3, 1, 1, 1} each number resembles a category(question type) with subcategories(questions), where 2 is the question whose answer i want to show after 3 clicks on the screen(numbers are chosen randomly), how do I do that, had something in mind but it turned out too complicated.

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

Answer by MickyX · May 03 at 07:24 PM

Just to check, if someone clicks 3 times you want to return the third item in the list?

So 3 clicks would return 2? 4 clicks would return 3?

if you have the number of clicks just return based on the index-1 due to list starting at zero

list[numberOfClicks-1]

Comment
Add comment · Show 3 · 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 SwathedOrange · May 03 at 10:04 PM 0
Share

No, no, every click a category would change, thus a new question would appear, but specifically for number 2, when its chosen randomly a text would appear saying smth like “blink until told otherwise” and then after 3 clicks(3 questions changed) a screen would appear “you can stop blinking”

avatar image MickyX SwathedOrange · May 03 at 11:01 PM 0
Share

Oh okay, I think I get it

here is what I would do, create a list of objects and add new objects into that when you have a type 2 question, this will allow for multiple type 2 questions to be running at the same time.

When a type 2 question comes up call CreateNewShowAfterClicks() and pass in the number of clicks you want to wait for and the message to be displayed when completed.

On each click call IncreaseCountersAndCheck() this will increase each of the none completed wait for click objects and display the message if the clicks is equal to your set number of clicks, you should be able to make the below fit in to your script

 public List<ShowAfterClicks> afterClicksList = new List<ShowAfterClicks>();
 
 public class ShowAfterClicks
 {
     public int numOfClicks;
     public string message;
     public int clickCounter =0;
 }
 
 private void CreateNewShowAfterClicks(int numOfClicks, string message)
 {
         ShowAfterClicks tempVar = new ShowAfterClicks();
         tempVar.numOfClicks = numOfClicks;
         tempVar.message = message;
         afterClicksList.Add(tempVar);
 }
 
     private void IncreaseCountersAndCheck()
     {
         //Loop though all where the click counter is less than num of clicks
         foreach (var item in (from x in afterClicksList where x.clickCounter < x.numOfClicks select x).ToList())
         {
             item.clickCounter++;
             if(item.clickCounter > item.numOfClicks)
             {
                 //Display item.message
             }
         }
     }
  
avatar image SwathedOrange MickyX · May 04 at 10:28 AM 0
Share

Thanks a lot!

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

147 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

Related Questions

How to stop instantiating a certain object / objects from a list . 3 Answers

A node in a childnode? 1 Answer

How do I Create 5 Random Racers? 2 Answers

Randomly remove list values 1 Answer

Error when transferring items from one list to another 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