adding dynamic amount of gameObjects from stage into Array

Hi guys,

I was wondering if there was an easy way to do the following.I have a script with a List that will contain a dynamic amount of Transforms.

What I am trying to accomplish is this:

Drag a dynamic amount of Transforms onto a variable field in the Inspector so they get Added to the List of that Script.

In C# you can do

using UnityEngine;
using System.Collections;
using System.Collections.Generic;

public class planeFitting : MonoBehaviour 
{
	public List<Transform>  _tranList;
}

In the inspector you’ll have a field that can be expanded, within in which you can specify how many transforms you want to add, then drag transforms into the list.

@ Noisecrime

That’s awesome! I started with javascript first, but dove into C# yesterday. Inheritance/typing make sit way better ( I think).
I tried you approach in Javascript but that failed (but I might have done something wrong there), in C it works fine!

Got to say that the responses on this forum are awesome, hope to contribute soon!

You could use a standard built-in array:

var transformArray : Transform[];

The number of elements is editable in the inspector, although it can’t be resized at runtime. If you want to use a dynamic list, Noisecrime’s code in JS is:

import System.Collections.Generic;

_tranList : List.<Transform>;

It’s pretty much the same in JS, but with less boilerplate code.

–Eric