The script below is added to an empty game object WeaponGroup
, which can be populated using the editor. I have made a new game object WeaponGroups
which should have a script SetupWeaponGroupsScript
. How can I transfer the properties below so that each WeaponGroup
(SetupWeaponGroupsScript
will have an array of WeaponGroup
objects) is setup in a way similar to what is done below, so that I make the SetupWeaponsScript
properties hidden to the inspector and populate them through SetupWeaponGroupsScript
?
public class SetupWeaponsScript {
// Here's our tuple combining a weapon prefab and a direction.
[System.Serializable]
public struct DirectedWeapon {
public WeaponScript weapon;
public WeaponScript.Direction direction;
}
// The prefabs array is now this tuple type.
public DirectedWeapon[] weaponPrefabs;
public WeaponScript[] weapons;
void Start ()
{
weapons = new WeaponScript[weaponPrefabs.Length];
for (int i = 0; i < weaponPrefabs.Length; i++)
{
// Using typed Instantiate to save a GetComponent call.
weapons[i] = Instantiate<WeaponScript>(weaponPrefabs[i].weapon);
weapons[i].weaponDir = weaponPrefabs[i].direction;
}
}
}
In other words I'd like to have the following hierarchy in the editor: