Hello all,
i need to add game objects in a 2D array directly in the inspector.
i am trying to do it like:
var aGrid = new GameObject[,];
but it does not allow me add the game object in it.
please help me if any1 can.
Thanks in Advance!
Niki.j
Hello all,
i need to add game objects in a 2D array directly in the inspector.
i am trying to do it like:
var aGrid = new GameObject[,];
but it does not allow me add the game object in it.
please help me if any1 can.
Thanks in Advance!
Niki.j
I dont think you can add array elements in the inspector even if it is public. Why not do it with code? It won’t be difficuilt and it will make your code more flexible anyway.
Here is the csharp code i dont know about Unityscript but in cs its work fine for me.
GameObject[,] myObject= new GameObject[2,4];
myObject[0,0]=gameObject;
myObject[0,1]=gameObject;
myObject[0,2]=gameObject;
myObject[0,3]=gameObject;
here is UnityScript:
var myObject:GameObject[,]= new GameObject[2,4];
myObject[0,0]=gameObject;
myObject[0,1]=gameObject;
myObject[0,2]=gameObject;
myObject[0,3]=gameObject;
print(myObject[0,3].name);
Hello,
thanks for the suggestions,the post are really very useful.
but i have around 250 static gameObjects,that i have to add in the scene.and i want to do it like just drop and down all my objects (it should does not matter how many they are) and i am able to use my script without any modifications.
i dont have option to use them as a prefab. that is why i was trying to do as above i asked for.
Thanks for the help!
any more improvements,suggestions,critics will be very much welcome.
Thanks in Advance!
Niki.j
There are a couple different ways to set this up - which is the best would depend on how big your grid is, how densely populated, and what kind of objects you’re placing on it.
For example, one way would be to have an “Add to Grid” component on the objects you’re placing, which determines their grid position from their world position (rounding) on startup and adds them to the grid, allowing you to lay it out visually.
Another would be to read the grid data from a separate file, and create/setup the objects through code. It all depends on what your parameters are.