I’ve got a script which populates a gameboard with procedurally generated tiles (by repeatedly calling Instantiate), which have scripts on them that need to be aware of some global variables and of some values that I want to assign to each tile at creation time.
Assume a prefab with a script called MyTile and you are setting the creation order (iCreate).
for (int i = 0; i < iTileCount, i++)
{
GameObject go = Instantiate(goPrefab);
MyTile mt = go.GetComponent<MyTile>();
mt.iCreate = i;
}
Note Start() will not have been called at this point.
You can
for( int i = 0; i < numberOfTiles; ++i )
{
// Catch your instantiated tile
//(C#)
Tile tempTile = Instantiate( prefabTile, (specificLocation), (specificRotation) ) as Tile;
// (Javascript)
var tempTile : Tile;
tempTile = Instantiate(....);
//Set the public variable
tempTile.publicIntValue = 10;
}
I am not exactly sure about the global variables you are talking about. Hopes that this segment of codes is what you are looking for.