現在のターン数を画面に表示する


ターン数を画面に表示する
using System.Collections;
using TMPro;
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;
// ★追加
private int currentTurnCount = 0;
public TextMeshProUGUI turnLabel;
void Start()
{
StartCoroutine(nameof(SpawnRoutine));
// ★追加
turnLabel.text = currentTurnCount + "/" + database.spawnList.Count;
}
private IEnumerator SpawnRoutine()
{
yield return new WaitForSeconds(2f);
for (int i = 0; i < database.spawnList.Count; i++)
{
// ★追加
currentTurnCount += 1;
turnLabel.text = currentTurnCount + "/" + database.spawnList.Count;
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;
if (!string.IsNullOrEmpty(database.spawnList[i].tag))
{
bot.tag = database.spawnList[i].tag;
}
yield return new WaitForSeconds(1f);
}
yield return new WaitForSeconds(2f);
}
}
}


【Unity6版】TowerDX(全 回)
他のコースを見る

ターン数を画面に表示する
using System.Collections;
using TMPro;
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;
// ★追加
private int currentTurnCount = 0;
public TextMeshProUGUI turnLabel;
void Start()
{
StartCoroutine(nameof(SpawnRoutine));
// ★追加
turnLabel.text = currentTurnCount + "/" + database.spawnList.Count;
}
private IEnumerator SpawnRoutine()
{
yield return new WaitForSeconds(2f);
for (int i = 0; i < database.spawnList.Count; i++)
{
// ★追加
currentTurnCount += 1;
turnLabel.text = currentTurnCount + "/" + database.spawnList.Count;
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;
if (!string.IsNullOrEmpty(database.spawnList[i].tag))
{
bot.tag = database.spawnList[i].tag;
}
yield return new WaitForSeconds(1f);
}
yield return new WaitForSeconds(2f);
}
}
}


現在のターン数を画面に表示する