- Home /
Creating a record of values generated with Random.Range
First I want to say thanks to al the people who answer these questions. I just made my first working game which is a Rubiks Cube. There's more to do to make it officially "complete", but it works. It's really hard to break, it shuffles itself on command and it's actually kind of fun. There is no way I would have made it this far without the information I learned in these Answers. Ironically, this is my first time asking a question. So here it is...
In order to randomly shuffle the cube, I replace user input control with the following code that accounts for all 18 possible 90 degree rotations that can be made on a given move. Can randomly generated values be stored such as in a list or some time of data collection? If it is possible to store these 18 outcomes, could someone please recommend the datatype(s) to consider and point me in the right direction as far as capturing this data as it happens in realtime. Thanks!
void GenerateAxisA()
// Generates values for aAxis(rotation axis)
// and aPos(face to rotate)
// Keeps generating random rotations until shuffleCount = 0
{
if(_readyToShuffle)
{
int a=Random.Range(1,7);
int p=Random.Range(-1,2);
if(a==1)
{
aAxis=new Vector3(1f,0f,0f);
aPos = new Vector3((float)p,0f,0f);
_xRoto=true;
_yRoto=false;
_zRoto=false;
}
if(a==2)
{
aAxis=new Vector3(-1f,0f,0f);
aPos = new Vector3((float)p,0f,0f);
_xRoto=true;
_yRoto=false;
_zRoto=false;
}
if(a==3)
{
aAxis =new Vector3(0f,1f,0f);
aPos = new Vector3(0f,(float)p,0f);
_yRoto=true;
_xRoto=false;
_zRoto=false;
}
if(a==4)
{
aAxis =new Vector3(0f,-1f,0f);
aPos = new Vector3(0f,(float)p,0f);
_yRoto=true;
_xRoto=false;
_zRoto=false;
}
if(a==5)
{
aAxis =new Vector3(0f,0f,1f);
aPos = new Vector3(0f,0f,(float)p);
_zRoto=true;
_yRoto=false;
_xRoto=false;
}
if(a==6)
{
aAxis =new Vector3(0f,0f,-1f);
aPos = new Vector3(0f,0f,(float)p);
_zRoto=true;
_yRoto=false;
_xRoto=false;
}
shuffleCount-=1;
_axisGenerated=true;
}
}
Answer by m4c0 · Mar 25, 2015 at 02:21 AM
You can use a generic List (System.Collections.Generic) with a "struct" representing your transformations ("a" and "p", it seems).
Thanks for the quick reply. Looks like I'm off to do my homework. Very promising so far. Lots of new stuff to sort out. Lots of ins. Lots of outs. Lots of what have yous....
@yoeyyutch : Hey just a piece of advice , it better if you use Switch Case than If Statements. $$anonymous$$ore optimized .. Have a nice day
Thanks Vulcan. So what you guys are saying is that I need to add some new tricks to my repertoire. I can't argue with that. Have a splendid day as well.
Ok the deeper I dig into my one script, the more I realize that I have some fundamental changes to implement before I can tackle more advanced functionality like this. I think we can close this case for now. Thanks again.