Can not access sub objects

I can’t seem to access sub objects of an array of objects.
I’ve tried the suggestions in the Answers, but I still keep getting error messages. One says that things are “not a member of Object”. The latest error says:

ApplicationException: Argument is not enumerable (does not implement System.Collections.IEnumerable). Boo.Lang.Runtime.RuntimeServices.GetEnumerable (System.Object enumerable)

What I am trying to do is have 10 levels each with 12 sphere triggers in. When a whole level is triggered at the same time an action takes place. But to do this I need to be able to access the levels ID and the ID of each of the sub objects. Pleas can someone help?

This is my latest script (It brings up the above error message).

var levels: Array;
var level: Array;
var thisLevel: GameObject;
var triggerSphere: Transform[];

function Start () {

levels = GameObject.FindGameObjectsWithTag ("Level");

	for (level in levels) {
		
		
		Debug.Log ("Level = " + level);
		for (var tS: GameObject in level){
		
		}
		
	
	}
		


}

1 Answer

1

You have to access child objects via the transform of the GameObject. Try this:

#pragma strict
 
var levels: GameObject[];
var level: GameObject;
var thisLevel: GameObject;
var triggerSphere: Transform[];

function Start () {

levels = GameObject.FindGameObjectsWithTag ("Level");
	for (level in levels) {
		Debug.Log ("Level = " + level);
		for (var tS : Transform in level.transform){

		}
	}
}

Sorry. It didn't work. I got the compile error: Assets/MenueSceneFolder/Scripts/TallyFilled-NEW.js(16,50): BCE0019: 'transform' is not a member of 'Object'.

Probably because you haven't declared your "level" variable as a GameObject. Try doing that like in the script posted.

Thanks vision810 you are correct. My mistake.