- Home /
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.
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]
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”
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
}
}
}
Your answer
Follow this Question
Related Questions
A node in a childnode? 1 Answer
How to stop instantiating a certain object / objects from a list . 3 Answers
Pick between two floats 2 Answers
Random element from the list 1 Answer