敵の製造装置を作る

コルーチンで敵を生み出す
using System.Collections; using System.Collections.Generic; using UnityEngine; public class EnemyGene : MonoBehaviour { public GameObject[] enemyPrefabs; void Start() { StartCoroutine(EGene()); } private IEnumerator EGene() { yield return new WaitForSeconds(3f); while (true) { // 1つ目の敵を1.5秒ごとに3体作成する。 for (int i = 0; i < 3; i++) { GameObject enemyX = Instantiate(enemyPrefabs[0], transform.position, Quaternion.identity); Destroy(enemyX, 7.0f); yield return new WaitForSeconds(1.5f); } yield return new WaitForSeconds(1f); // 2つ目の敵を1.5秒ごとに4体作成する。 for (int j = 0; j < 4; j++) { GameObject enemyY = Instantiate(enemyPrefabs[1], transform.position, Quaternion.identity); Destroy(enemyY, 7.0f); yield return new WaitForSeconds(1.5f); } yield return new WaitForSeconds(1f); // 3つ目の敵を1.5秒ごとに5体作成する。 for (int k = 0; k < 5; k++) { GameObject enemyZ = Instantiate(enemyPrefabs[2], transform.position, Quaternion.identity); Destroy(enemyZ, 7.0f); yield return new WaitForSeconds(1.5f); } yield return new WaitForSeconds(1f); } } }
C#



【2022版】AR_Project(全9回)
1 | キャラクターをAR鑑賞する |
2 | ★チャレンジ課題 |
3 | ARシューティングゲームの開発 |
4 | ★チャレンジ課題 |
5 | 敵の製造装置を作る |
6 | 敵を破壊する |
7 | オリジナルのカーソルを作成する |
8 | カウンターを作成する |
9 | ★チャレンジ課題 |

コルーチンで敵を生み出す
using System.Collections; using System.Collections.Generic; using UnityEngine; public class EnemyGene : MonoBehaviour { public GameObject[] enemyPrefabs; void Start() { StartCoroutine(EGene()); } private IEnumerator EGene() { yield return new WaitForSeconds(3f); while (true) { // 1つ目の敵を1.5秒ごとに3体作成する。 for (int i = 0; i < 3; i++) { GameObject enemyX = Instantiate(enemyPrefabs[0], transform.position, Quaternion.identity); Destroy(enemyX, 7.0f); yield return new WaitForSeconds(1.5f); } yield return new WaitForSeconds(1f); // 2つ目の敵を1.5秒ごとに4体作成する。 for (int j = 0; j < 4; j++) { GameObject enemyY = Instantiate(enemyPrefabs[1], transform.position, Quaternion.identity); Destroy(enemyY, 7.0f); yield return new WaitForSeconds(1.5f); } yield return new WaitForSeconds(1f); // 3つ目の敵を1.5秒ごとに5体作成する。 for (int k = 0; k < 5; k++) { GameObject enemyZ = Instantiate(enemyPrefabs[2], transform.position, Quaternion.identity); Destroy(enemyZ, 7.0f); yield return new WaitForSeconds(1.5f); } yield return new WaitForSeconds(1f); } } }
C#



敵の製造装置を作る