マネーポイントが不足すると負けになる仕組みの実装

マネーポイント不足で負け
using System.Collections;
using UnityEngine;
using UnityEngine.SceneManagement;
public class BotSpawn : MonoBehaviour
{
public enum TeamType { Blue, Red };
public TeamType team;
public PointManager pm;
public SpawnDatabase database;
public GameObject botPrefab;
public GameObject spawnPoint;
void Start()
{
StartCoroutine(nameof(SpawnRoutine));
}
private IEnumerator SpawnRoutine()
{
yield return new WaitForSeconds(2f);
for (int i = 0; i < database.spawnList.Count; i++)
{
for (int j = 0; j < database.spawnList[i].repeatCount; j++)
{
int speed = database.spawnList[i].moveSpeed;
int HP = database.spawnList[i].HP;
int botPrice = speed * HP * 10;
if (team == TeamType.Blue)
{
// ★追加
if (pm.bluePoint < botPrice)
{
SceneManager.LoadScene("BlueLose");
yield break; // コルーチンを完全に抜ける
}
pm.ReduceBluePoint(botPrice);
}
else
{
// ★追加
if (pm.redPoint < botPrice)
{
SceneManager.LoadScene("RedLose");
yield break;
}
pm.ReduceRedPoint(botPrice);
}
GameObject bot = Instantiate(botPrefab, spawnPoint.transform.position, transform.rotation);
bot.GetComponent<BotMove>().moveSpeed = speed;
bot.GetComponent<BotHP>().HP = HP;
yield return new WaitForSeconds(1f);
}
yield return new WaitForSeconds(2f);
}
}
}


【Unity6版】TowerDX(全 回)
他のコースを見る
マネーポイント不足で負け
using System.Collections;
using UnityEngine;
using UnityEngine.SceneManagement;
public class BotSpawn : MonoBehaviour
{
public enum TeamType { Blue, Red };
public TeamType team;
public PointManager pm;
public SpawnDatabase database;
public GameObject botPrefab;
public GameObject spawnPoint;
void Start()
{
StartCoroutine(nameof(SpawnRoutine));
}
private IEnumerator SpawnRoutine()
{
yield return new WaitForSeconds(2f);
for (int i = 0; i < database.spawnList.Count; i++)
{
for (int j = 0; j < database.spawnList[i].repeatCount; j++)
{
int speed = database.spawnList[i].moveSpeed;
int HP = database.spawnList[i].HP;
int botPrice = speed * HP * 10;
if (team == TeamType.Blue)
{
// ★追加
if (pm.bluePoint < botPrice)
{
SceneManager.LoadScene("BlueLose");
yield break; // コルーチンを完全に抜ける
}
pm.ReduceBluePoint(botPrice);
}
else
{
// ★追加
if (pm.redPoint < botPrice)
{
SceneManager.LoadScene("RedLose");
yield break;
}
pm.ReduceRedPoint(botPrice);
}
GameObject bot = Instantiate(botPrefab, spawnPoint.transform.position, transform.rotation);
bot.GetComponent<BotMove>().moveSpeed = speed;
bot.GetComponent<BotHP>().HP = HP;
yield return new WaitForSeconds(1f);
}
yield return new WaitForSeconds(2f);
}
}
}


マネーポイントが不足すると負けになる仕組みの実装