0
以下のスクリプトは空のゲームオブジェクトWeaponGroup
に追加されます。このオブジェクトはエディタを使用して入力できます。私は新しいゲームオブジェクトWeaponGroups
を作成しました。これにはスクリプトSetupWeaponGroupsScript
が必要です。それぞれWeaponGroup
(SetupWeaponGroupsScript
はWeaponGroup
オブジェクトの配列を持ちます)が以下のような方法で設定されるように、以下のプロパティを転送することができます。プロパティをインスペクタに非表示にして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;
}
}
}
グラフィカルに、私は新しいスクリプトSetupWeaponGroupsScript
用のエディタで、次の階層を持っているしたいと思います: