“the issue then, is, how do i associate:…”
I hate dragging things in to the editor, it seems cheap. I often sit one “model” whatever it is, under the master game object. I just get the model and duplicate it, and customize it for each one. In this trivial code below, there’s an array with names like “Spaceship” “Lasercannon”. all the sprite names happen to be pSpaxeship, pLasercannon and so on.
The code in the For Loop carefully builds all the 10 or so buttons. Now, the whole ‘model button’ system, is self-contained and has everything it needs inside it. Note that it’s calling setup functions and so on in the individual buttons.
So once again, a common approach. You might have “City” mega object. in there you will have ONE “building”. Name it ‘StarterBuilding’ or ‘Model Building’. In itself, that could be a huge system with many subcomponents and scripts. In your city script, find the “StarterBuilding” below you, and instantiate 200 buildings, or however many. For each one, do all necessary specific startup.
You can freely work on ‘Model Building’ whenever you need to do so.
So that’s perhaps part of what you’re asking. I like to have a “model” building, button, or whatever it is. the thing over it, takes the one named “model” and makes many of them. Note the very handy “FindUnderHereNamed” fragment.
#pragma strict
import System.Collections.Generic;
private var myProjectiles:List.<bouncyButton>;
private var kPL:int;
function _buildButtonsAtLaunchTime()
{
myProjectiles = new List.<bouncyButton>();
// NOTE
var modelButton:GameObject
= FindUnderHereNamed("modelButton").gameObject;
// NOTE
modelButton.transform.localPosition = Vector3(0, 3, 0);
var widthModel:float = modelButton.collider.bounds.size.x;
var heightModel:float = modelButton.collider.bounds.size.y;
var widthGap:float = widthModel * 0.100;
kPL = candc.projectileNames.length;
for ( var i:int=0; i<=kPL; ++i )
{
var newy:GameObject = Instantiate( modelButton );
newy.transform.parent = transform;
newy.name = "b" + candc.projectileNames*;*
var newAcross:float = ( widthModel + widthGap ) * i;
newy.transform.localPosition = Vector3(newAcross, 0, 0);
newy.GetComponent(bouncyButton).setThePridTKImage(
i, “p”+candc.projectileNames );
myProjectiles.Add( newy.GetComponent(bouncyButton) );
}
Debug.Log(“built buttons. didn’t use any damn editor dragging”);
}
//////////////////////////////////////////////
function FindUnderHereNamed(name:String):Transform
{
var transforms = transform.GetComponentsInChildren(Transform);
for (var t : Transform in transforms)
{
if (t.name == name) return t;
}
return null;
}
//////////////////////////////////////////////