- Home /
jagged array in c# from different sized units
I'm trying to do something like this:
from a set of 5 gameobjects from a list, store them in an array on Start and then when the array coordinates are changed (now on cord 0,1 etc) it tells the gameObject in that slot to be active. Each game object carries information about it's own cell size.
Not really sure where to start with Jagged arrays, have been looking at various examples but nothing really fits my use case.
If anyone could suggest something that is along these lines it would be greatly appreciated. (I'm not a big fan of large generic code and classes that solve the universe, so anything focused to this is more appreciated, kind of why I'm stuck really)
Answer by RudyTheDev · Sep 13, 2015 at 12:02 PM
If I understand correctly, you don't need a jagged array. Since GameObjects (and I assume you have a custom MB class) are reference types, you can have a full 2d array and have 0,0 1,0 2,0 all point to the same GameObject. You would need to add the base location to the each GameObject if you need to remove/retrieve that. When you "add" a GameObject to the array, you just iterate along it's width/height and fill the appropriate number of array cells with a reference to it.
Your answer
![](https://koobas.hobune.stream/wayback/20220612033548im_/https://answers.unity.com/themes/thub/images/avi.jpg)
Follow this Question
Related Questions
Multiple Cars not working 1 Answer
Distribute terrain in zones 3 Answers
Double Parse a text file into 2d array or jagged array 1 Answer
How to implement and Access Jagged Array C# 1 Answer
Best way to access player's gameobject across network 2 Answers