Search Unity

  1. Welcome to the Unity Forums! Please take the time to read our Code of Conduct to familiarize yourself with the forum rules and how to post constructively.
  2. We have updated the language to the Editor Terms based on feedback from our employees and community. Learn more.
    Dismiss Notice
  3. Join us on November 16th, 2023, between 1 pm and 9 pm CET for Ask the Experts Online on Discord and on Unity Discussions.
    Dismiss Notice

How to change Size in Transform[]

Discussion in 'Scripting' started by Sameem157, Oct 13, 2019.

  1. Sameem157

    Sameem157

    Joined:
    Mar 4, 2018
    Posts:
    4
    Hi, I was wondering if its possible to change the size when using transform[].
    I am beginner to unity and i'm using c# if that helps.
     
  2. Bogaland

    Bogaland

    Joined:
    Feb 19, 2017
    Posts:
    32
  3. Sameem157

    Sameem157

    Joined:
    Mar 4, 2018
    Posts:
    4
  4. WarmedxMints

    WarmedxMints

    Joined:
    Feb 6, 2017
    Posts:
    1,035
    If you want an array with a dynamic size, use a list instead as it makes the process much easier.
     
  5. Sameem157

    Sameem157

    Joined:
    Mar 4, 2018
    Posts:
    4
    How would I do that? Thanks for your help BTW
     
  6. Vryken

    Vryken

    Joined:
    Jan 23, 2018
    Posts:
    2,106
    Here's a guide on Lists: https://www.c-sharpcorner.com/article/c-sharp-list/
    In a nutshell, Lists are pretty much just arrays with a dynamic size. There's obviously more to them than just that, however.

    If you want to change an array of Transforms to a List of Transforms, the syntax is this:
    Code (CSharp):
    1. List<Transform> transforms;
    One crucial thing to remember is that Lists are objects, meaning unlike arrays, they do have to be instantiated before they can be used:
    Code (CSharp):
    1. List<Transform> transforms = new List<Transform>();
     
  7. Sameem157

    Sameem157

    Joined:
    Mar 4, 2018
    Posts:
    4
    Thanks iv'e spent hours trying to figure this out.
    Thanks again for your help
     
  8. garylinen

    garylinen

    Joined:
    Dec 19, 2019
    Posts:
    3
    try this one too, more examples on...C# List