Search Unity

  1. Good news ✨ We have more Unite Now videos available for you to watch on-demand! Come check them out and ask our experts any questions!
    Dismiss Notice

Multiple Array Class Instantiation

Discussion in 'Scripting' started by Brandon3DS, Jul 15, 2009.

  1. Brandon3DS

    Brandon3DS

    Joined:
    Apr 6, 2009
    Posts:
    5
    Hello guys,

    I am having a problem with finding the correct syntax for instantiating an array class within an array class. Any help would be much appreciated.

    Here is my code:

    Code (csharp):
    1. cArrayList = new Array;
    2.  
    3. class charClass{
    4.     var mc : miscClass[];
    5. }
    6.  
    7. class miscClass{
    8.     var data1 : int;
    9.     var data2 : string;
    10. }
    11.  
    12.  
    13. cArrayList.Add(new charClass());
    14. cArrayList[0].mc = new miscClass();
    15.  
    The above code works when miscClass isn't an array, but how can I instantiate it as an array?

    Using:

    Code (csharp):
    1.  
    2. cArrayList[0].mc = new miscClass();
    3.  
    dosn't work.


    Thanks,
    Brandon
     
  2. Brandon3DS

    Brandon3DS

    Joined:
    Apr 6, 2009
    Posts:
    5
    Nevermind, I found an alternative method:

    Code (csharp):
    1.  
    2. cArrayList = new Array;
    3.  
    4. class charClass{
    5.    var mc : miscClass[];
    6.    var mca = new Array;
    7. }
    8.  
    9. class miscClass{
    10.    var data1 : int;
    11.    var data2 : string;
    12. }
    13.  
    14.  
    15. cArrayList.Add(new charClass());
    16. cArrayList[0].mca.Add(new mc);
    17. cArrayList[0].mca[0].data1 = 5;
    18. cArrayList[0].mca[0].data2 = "Hello";
    19.  
     
unityunity