Search Unity

Setting in built array size in script.

Discussion in 'Scripting' started by grimmy, Sep 2, 2009.

  1. grimmy

    grimmy

    Joined:
    Feb 2, 2009
    Posts:
    409
    How do I set the size of an in built array using script?

    I would normally just set the array size in the inspector but these objects are instantiated at runtime so I cant.
     
  2. duck

    duck

    Unity Technologies

    Joined:
    Oct 21, 2008
    Posts:
    358
    You can declare the size when you declare the array variable, like this:

    Code (csharp):
    1. int[] myNumbers = new int[10];
    Read more about built-in arrays here.

    If you're using Javascript, it's:

    Code (csharp):
    1. var myNumbers : int[] = new int[10];
    hope this helps!

    - Ben