敵の発生装置の作成①(コルーチンの復習)
![3c98901d ee3a 4f6c a22c 2ca55580ceb9](https://codegenius.org/uploads/slide/image/7616/3c98901d-ee3a-4f6c-a22c-2ca55580ceb9.jpeg)
敵を拠点から生み出す(コルーチン)
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class EnemyGene : MonoBehaviour
{
public GameObject enemyPrefab;
void Start()
{
StartCoroutine(Gene());
}
private IEnumerator Gene()
{
// 処理Aを3回繰り返す
for (int i = 0; i < 3; i++)
{
// 「0.2秒ごとに敵を発生させる」という処理を5回繰り返す(処理A)
for (int j = 0; j < 5; j++)
{
// 敵を発生させる
Instantiate(enemyPrefab, transform.position, Quaternion.identity);
// 待機(0.2秒)
yield return new WaitForSeconds(0.2f);
}
yield return new WaitForSeconds(1f);
}
}
}
![271c3d10 2b87 448a 9d93 f95dcddd3f63](https://codegenius.org/uploads/slide/image/7617/271c3d10-2b87-448a-9d93-f95dcddd3f63.jpeg)
![Eb161a7c f5a1 4dc0 889f 1f5e973832e5](https://codegenius.org/uploads/slide/image/7618/eb161a7c-f5a1-4dc0-889f-1f5e973832e5.jpeg)
![711622a0 9024 407e 8187 6572d56aed77](https://codegenius.org/uploads/slide/image/7619/711622a0-9024-407e-8187-6572d56aed77.jpeg)
![B6f6aee1 fa0a 407e 940a 0ff91e3b95e7](https://codegenius.org/uploads/slide/image/7620/b6f6aee1-fa0a-407e-940a-0ff91e3b95e7.jpeg)
![37a2273b 838f 4e97 9bfa 7a126f937bf1](https://codegenius.org/uploads/slide/image/7621/37a2273b-838f-4e97-9bfa-7a126f937bf1.jpeg)
【2021版】Danmaku(基礎/全55回)
他のコースを見る![3c98901d ee3a 4f6c a22c 2ca55580ceb9](https://codegenius.org/uploads/slide/image/7616/3c98901d-ee3a-4f6c-a22c-2ca55580ceb9.jpeg)
敵を拠点から生み出す(コルーチン)
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class EnemyGene : MonoBehaviour
{
public GameObject enemyPrefab;
void Start()
{
StartCoroutine(Gene());
}
private IEnumerator Gene()
{
// 処理Aを3回繰り返す
for (int i = 0; i < 3; i++)
{
// 「0.2秒ごとに敵を発生させる」という処理を5回繰り返す(処理A)
for (int j = 0; j < 5; j++)
{
// 敵を発生させる
Instantiate(enemyPrefab, transform.position, Quaternion.identity);
// 待機(0.2秒)
yield return new WaitForSeconds(0.2f);
}
yield return new WaitForSeconds(1f);
}
}
}
![271c3d10 2b87 448a 9d93 f95dcddd3f63](https://codegenius.org/uploads/slide/image/7617/271c3d10-2b87-448a-9d93-f95dcddd3f63.jpeg)
![Eb161a7c f5a1 4dc0 889f 1f5e973832e5](https://codegenius.org/uploads/slide/image/7618/eb161a7c-f5a1-4dc0-889f-1f5e973832e5.jpeg)
![711622a0 9024 407e 8187 6572d56aed77](https://codegenius.org/uploads/slide/image/7619/711622a0-9024-407e-8187-6572d56aed77.jpeg)
![B6f6aee1 fa0a 407e 940a 0ff91e3b95e7](https://codegenius.org/uploads/slide/image/7620/b6f6aee1-fa0a-407e-940a-0ff91e3b95e7.jpeg)
![37a2273b 838f 4e97 9bfa 7a126f937bf1](https://codegenius.org/uploads/slide/image/7621/37a2273b-838f-4e97-9bfa-7a126f937bf1.jpeg)
敵の発生装置の作成①(コルーチンの復習)