Hi guys,
I have a bunch of puzzle pieces that come in from Maya (as an fbx). They are parented to a ‘puzzleParent’ object. I want to iterate through all child objects of puzzleParent and store them in an array to manipulate later on.
My code is complaining about not being an instance … NullReferenceException: Object reference not set to an instance of an object … on the line where I’m trying to add the object to my array.
Here is the code and any help would be more than welcome …
private var gamePieces : Array;
function Awake () {
// FIRST WE FIND THE PUZZLE PARENT OBJECT, TO WHICH ALL PUZZLE PIECES ARE CHILD OBJECTS
var puzzleParent : GameObject;
puzzleParent = GameObject.Find("puzzleParent");
puzzle=puzzleParent.transform;
// ITERATE THROUGH CHILD OBJECTS (OF PUZZLEPARENT) AND STORE REFERENCES TO THEM
for( var aPuzzlePiece : Transform in puzzle ) {
var a=aPuzzlePiece.transform;
gamePieces.Add(a);
}
resetPieces();
}
Thanks!
Jeff.