敵の発生装置の作成②(ランダムの活用)

発生する敵が毎回ランダム
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class EnemyGene : MonoBehaviour
{
// ★改良
public GameObject[] enemyPrefabs;
void Start()
{
StartCoroutine(Gene());
}
private IEnumerator Gene()
{
while (true)
{
for (int j = 0; j < 5; j++)
{
// ★追加
// 毎回ランダムにnumの数字が決まる。
int num = Random.Range(0, enemyPrefabs.Length);
// ★改良
Instantiate(enemyPrefabs[num], transform.position, Quaternion.identity);
yield return new WaitForSeconds(0.2f);
}
yield return new WaitForSeconds(1f);
}
}
}



【2021版】Danmaku(基礎/全55回)
他のコースを見る
発生する敵が毎回ランダム
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class EnemyGene : MonoBehaviour
{
// ★改良
public GameObject[] enemyPrefabs;
void Start()
{
StartCoroutine(Gene());
}
private IEnumerator Gene()
{
while (true)
{
for (int j = 0; j < 5; j++)
{
// ★追加
// 毎回ランダムにnumの数字が決まる。
int num = Random.Range(0, enemyPrefabs.Length);
// ★改良
Instantiate(enemyPrefabs[num], transform.position, Quaternion.identity);
yield return new WaitForSeconds(0.2f);
}
yield return new WaitForSeconds(1f);
}
}
}



敵の発生装置の作成②(ランダムの活用)