レベル・システムの作成(コルーチンの改良)
![Fdb36fe4 f17d 4b00 a289 ea143a4de3ed](https://codegenius.org/uploads/slide/image/8055/fdb36fe4-f17d-4b00-a289-ea143a4de3ed.jpeg)
![D70b882f a243 45a9 a8d3 e01fc4da6916](https://codegenius.org/uploads/slide/image/8056/d70b882f-a243-45a9-a8d3-e01fc4da6916.jpeg)
![0a594645 5e95 4955 9270 d94b826a7505](https://codegenius.org/uploads/slide/image/8057/0a594645-5e95-4955-9270-d94b826a7505.jpeg)
レベル・システム
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);
}
}
}
![4f353381 ec5b 4e80 bbae 8ee802dbbc75](https://codegenius.org/uploads/slide/image/8058/4f353381-ec5b-4e80-bbae-8ee802dbbc75.jpeg)
【2021版】TowerD Ⅱ(全17回)
他のコースを見る![Fdb36fe4 f17d 4b00 a289 ea143a4de3ed](https://codegenius.org/uploads/slide/image/8055/fdb36fe4-f17d-4b00-a289-ea143a4de3ed.jpeg)
![D70b882f a243 45a9 a8d3 e01fc4da6916](https://codegenius.org/uploads/slide/image/8056/d70b882f-a243-45a9-a8d3-e01fc4da6916.jpeg)
![0a594645 5e95 4955 9270 d94b826a7505](https://codegenius.org/uploads/slide/image/8057/0a594645-5e95-4955-9270-d94b826a7505.jpeg)
レベル・システム
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);
}
}
}
![4f353381 ec5b 4e80 bbae 8ee802dbbc75](https://codegenius.org/uploads/slide/image/8058/4f353381-ec5b-4e80-bbae-8ee802dbbc75.jpeg)
レベル・システムの作成(コルーチンの改良)