- Home /
 
c# : Accessing Struct variables inside an Array
I am creating a grid of 10 x 10 boxes (Up to 100 x 100)
I would like to take a struct and initialize an array to a specific size.
If you suggest another method to achieving this result, please include an example.
public struct Box { // The struct used in the BoxArray public int firstModel; public Vector3 firstLocation; public int secondModel; public Vector3 secondLocation; public bool emptyBox; };
         public Box [] BoxArray;    //    Initializes the arra
         
         public class DoStuff : MonoBehaviour{
             //    How do I access and set the variables in BoxArray[5]? // using 5 as an example
         }
 
               
               Comment
              
 
               
               
               Best Answer 
               Wiki 
              
 
              Answer by idunlop_oefun · Sep 04, 2012 at 12:50 AM
 BoxArray = new Box[100];          // create the box array
 Box myBox = BoxArray[5];          // access 6th element (0 based index)
 
 
              Box[] BoxArray = new Box[100]
..works perfectly in Unity.
Thank you!
Your answer
 
             Follow this Question
Related Questions
Array or Data Structure with Vector3 as keys 2 Answers
Linking array of sets of vector3's together 1 Answer
instantiate problem help? 1 Answer
visible public struct 1 Answer
Using Array of Structs in Shader 1 Answer