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 /
avatar image
0
Question by yoeyyutch · Mar 25, 2015 at 02:11 AM · arraylistrandomrandom.rangerecording

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;
         }
     }

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

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).

Comment
Add comment · Show 4 · 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 yoeyyutch · Mar 25, 2015 at 03:23 AM 0
Share

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....

avatar image Noob_Vulcan · Mar 25, 2015 at 05:16 AM 0
Share

@yoeyyutch : Hey just a piece of advice , it better if you use Switch Case than If Statements. $$anonymous$$ore optimized .. Have a nice day

avatar image yoeyyutch · Mar 25, 2015 at 10:40 PM 0
Share

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.

avatar image yoeyyutch · Mar 29, 2015 at 03:35 PM 0
Share

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.

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

21 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

Related Questions

Selection list from Array Unity - Random - GameObjects array 1 Answer

How do you get different random numbers for each object array? 1 Answer

A node in a childnode? 1 Answer

Trying to avoid repeating elements on list (random.range) 1 Answer

Generate random no and active that GO using array 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