Very new to unity but fumbling my way around…
I don’t know if this is the right way to do things but I needed each of the ‘containers’ in my game to have an ID attached to them for interaction etc.
Someone suggested making a gameobject array and putting them all in that, then just using the array element as the ID. So I did that and it worked fine. I added them all in through the inspector, but it’s quite laborious doing it every time I have to change things, so thought I’d try and do it via code on game startup instead.
Tried this… (container_ids[ ] is the gameobject array)
var objects = GameObject.FindGameObjectsWithTag("Container");
foreach (var obj in objects) {
container_ids[obj] = GameObject;
}
This errors me “Expression denotes a type', where a
variable’, value' or
method group’ was expected”
What am I doing wrong?
EDIT: Figured how to fix it after messing about a little
var objects = GameObject.FindGameObjectsWithTag("Container");
int c = 0;
foreach (var obj in objects) {
container_ids[c] = obj;
c++;
}