Forum Discussion
gabriead
11 years agoHonored Guest
Random Selection of Objects for reaction time experiment?
Hi there,
I have a simple scene containing an avatar, a table and 4 different objects on the table.
I would like to randomly select pairs of two objects display them for 5 seconds and then randomly select a new pair.Every pair should only be displayed twice. This should proceed for a certain number of iterations.
Code I have so far: I have a class that deactivates all the objects at the beginning, calls a function that generates a random number and selects another function that activates and deactivates the pairs and checks how often this function has been called.
My Problem: It works for one iteration and then it does nothing. Could it be that the problem is, that I am using "yield WaitForSeconds(time)" in the "showBottleCup" function togehter with a for-loop?
I need something like: Wait for the function to activate/deactivate the objects and then go on with the next iteration.
What could the problem be? Is there a better solution to it?
I am thankful for every idea!
Thanks a lot!
Adrian
I have a simple scene containing an avatar, a table and 4 different objects on the table.
I would like to randomly select pairs of two objects display them for 5 seconds and then randomly select a new pair.Every pair should only be displayed twice. This should proceed for a certain number of iterations.
Code I have so far: I have a class that deactivates all the objects at the beginning, calls a function that generates a random number and selects another function that activates and deactivates the pairs and checks how often this function has been called.
My Problem: It works for one iteration and then it does nothing. Could it be that the problem is, that I am using "yield WaitForSeconds(time)" in the "showBottleCup" function togehter with a for-loop?
I need something like: Wait for the function to activate/deactivate the objects and then go on with the next iteration.
What could the problem be? Is there a better solution to it?
I am thankful for every idea!
Thanks a lot!
Adrian
public class TrialController : MonoBehaviour {
public GameObject bottle;
public GameObject cup;
public GameObject lamp;
public GameObject book;
private int NumBottleCupShown=0;
int numberOfLoops=3;
int timeIntervall=5;
int randomNumber;
void Start ()
{
cup.SetActive (false);
bottle.SetActive (false);
lamp.SetActive (false);
book.SetActive (false);
showRandomPair(this.numberOfLoops, this.timeIntervall);
}
void showRandomPair(int numLoops, int time)
{
//Loops for the number of permutations needed
for(int i=0; i<numLoops;i++)
{
//Generate random Number in the intervall of 0 to 3
this.randomNumber = Random.Range(0,3);
switch(randomNumber)
{
case 0: //StartCoroutine(showBottleBook(time));
break;
case 1: StartCoroutine(showBottleCup(time));
break;
case 2: //StartCoroutine(showBottleLamp(time));
break;
default: Debug.Log ("Something went wrong");
break;
}
}
}
IEnumerator showBottleCup(int time)
{
if (this.NumBottleCupShown <= 2) {
NumBottleCupShown++;
cup.SetActive (true);
bottle.SetActive (true);
yield return new WaitForSeconds(time);
cup.SetActive(false);
bottle.SetActive (false);
}
}
}
Quick Links
- Horizon Developer Support
- Quest User Forums
- Troubleshooting Forum for problems with a game or app
- Quest Support for problems with your device
Other Meta Support
Related Content
- 3 years ago