- Home /
How to add certain GameObjects with Booleans to an Array
I'm trying to add all GameObjects with a certain tag and boolean enabled.
Adding the tags was easy: Check = GameObject.FindGameObjectsWithTag("Target");
But it seems that I can't check GetComponent and then the boolean while setting up the array.
Any suggestions?
Please be more descriptive.
It would also be easier to help if you share some of your code.
What do you mean when you say you can't "check GetComponent and then the boolean while setting up the array"?
You haven't shared any code that uses Arrays.
Answer by jahroy · Dec 10, 2011 at 07:48 PM
Assuming you know how to get the array of GameObjects with a given tag, here is some code that will iterate over an array of GameObjects and assign the ones that are enabled to another array named activeThings.
To use this example you would set allThings equal to your array of GameObjects with a certain tag.
It demonstrates how you can build a Builtin array using a javascript dynamic array temporarily.
var allThings : GameObject [];
var activeThings : GameObject [];
function Start ()
{
var tempArray : Array = new Array();
for ( var thisThing : GameObject in allThings ) {
if ( thisThing.transform.renderer.enabled ) {
tempArray.Push(thisThing);
}
}
activeThings = tempArray.ToBuiltin(GameObject);
}
Your answer
Follow this Question
Related Questions
Get GameObject array from folder 1 Answer
Disable / enable script 2 Answers
Raycast and RaycastHit failure 2 Answers