unityチュートリアルのサバイバルシューターの中身をいじっていて、1つのゲームオブジェクトにEnemyManager.csが3つアタッチされていて戸惑ったのでメモ。
GameObject.GetComponentsで、コンポーネントの配列を取得する。
private EnemyManager[] scripts;
private const int INTERVAL_UPDATE = 100;
private int nextTargetScore = INTERVAL_UPDATE;
void Start() {
scripts = GameObject.Find("EnemyManager").GetComponents<EnemyManager>();
}
void Update() {
// 100ptごとにspown率を更新
if(score >= nextTargetScore){
nextTargetScore += INTERVAL_UPDATE;
foreach (var script in scripts)
{
script.UpdateSpown();
}
}
}