レベル・システムの作成(コルーチンの改良)



レベル・システム
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
// ★追加
using TMPro;
public class EnemyGene : MonoBehaviour
{
// ★追加
private int level = 1;
public TextMeshProUGUI levelLabel;
// ★改良
public GameObject[] enemyPrefabs;
void Start()
{
StartCoroutine(BotGene());
}
// ★追加
private void Update()
{
levelLabel.text = "LEVEL " + level;
}
private IEnumerator BotGene()
{
yield return new WaitForSeconds(2f);
// ★追加
while (true)
{
// ★改良
// EnmeyBot_A(最初は10体)
// レベルが上がるごとに、出現する敵の数も1つずつ増えていく(ポイント)
for (int i = 0; i < (9 + level); i++)
{
Instantiate(enemyPrefabs[0], transform.position, transform.rotation);
yield return new WaitForSeconds(1f);
}
yield return new WaitForSeconds(2f);
// ★追加
// EnemyBot_B(最初は3体)
for (int i = 0; i < (2 + level); i++)
{
Instantiate(enemyPrefabs[1], transform.position, transform.rotation);
yield return new WaitForSeconds(1f);
}
yield return new WaitForSeconds(2f);
// EnemyBot_C(最初は5体)
for (int i = 0; i < (4 + level); i++)
{
Instantiate(enemyPrefabs[2], transform.position, Quaternion.identity);
yield return new WaitForSeconds(1f);
}
// EnemyBot_D(最初は4体)
for (int i = 0; i < (3 + level); i++)
{
Instantiate(enemyPrefabs[3], transform.position, Quaternion.identity);
yield return new WaitForSeconds(1f);
}
level += 1; // レベルの更新
yield return new WaitForSeconds(3f);
}
}
}

【2021版】TowerD Ⅱ(全17回)
他のコースを見る


レベル・システム
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
// ★追加
using TMPro;
public class EnemyGene : MonoBehaviour
{
// ★追加
private int level = 1;
public TextMeshProUGUI levelLabel;
// ★改良
public GameObject[] enemyPrefabs;
void Start()
{
StartCoroutine(BotGene());
}
// ★追加
private void Update()
{
levelLabel.text = "LEVEL " + level;
}
private IEnumerator BotGene()
{
yield return new WaitForSeconds(2f);
// ★追加
while (true)
{
// ★改良
// EnmeyBot_A(最初は10体)
// レベルが上がるごとに、出現する敵の数も1つずつ増えていく(ポイント)
for (int i = 0; i < (9 + level); i++)
{
Instantiate(enemyPrefabs[0], transform.position, transform.rotation);
yield return new WaitForSeconds(1f);
}
yield return new WaitForSeconds(2f);
// ★追加
// EnemyBot_B(最初は3体)
for (int i = 0; i < (2 + level); i++)
{
Instantiate(enemyPrefabs[1], transform.position, transform.rotation);
yield return new WaitForSeconds(1f);
}
yield return new WaitForSeconds(2f);
// EnemyBot_C(最初は5体)
for (int i = 0; i < (4 + level); i++)
{
Instantiate(enemyPrefabs[2], transform.position, Quaternion.identity);
yield return new WaitForSeconds(1f);
}
// EnemyBot_D(最初は4体)
for (int i = 0; i < (3 + level); i++)
{
Instantiate(enemyPrefabs[3], transform.position, Quaternion.identity);
yield return new WaitForSeconds(1f);
}
level += 1; // レベルの更新
yield return new WaitForSeconds(3f);
}
}
}

レベル・システムの作成(コルーチンの改良)