ショップ・システムの作成②(敵の破壊数をカウントする)





敵ボットの破壊数のカウント
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using TMPro;
public class ShopManager : MonoBehaviour
{
private int[] enemyCount = new int[4];
public TextMeshProUGUI[] enemyLabel;
void Start()
{
enemyLabel[0].text = "" + enemyCount[0];
enemyLabel[1].text = "" + enemyCount[1];
enemyLabel[2].text = "" + enemyCount[2];
enemyLabel[3].text = "" + enemyCount[3];
}
public void AddEnemyCount(int num)
{
enemyCount[num] += 1;
enemyLabel[num].text = "" + enemyCount[num];
}
}



破壊数を増加させる
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class EnemyBot_A : EnemyBase
{
private void Start()
{
HP = 1;
}
// ★追加
public override void TakeDamage(int attackPower)
{
HP -= attackPower;
if (HP < 1)
{
Destroy(gameObject);
// ポイント(外部メソッドの呼び出し)
GameObject.Find("ShopManager").GetComponent<ShopManager>().AddEnemyCount(0); // 対応する番号を間違えないこと
}
}
}


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




敵ボットの破壊数のカウント
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using TMPro;
public class ShopManager : MonoBehaviour
{
private int[] enemyCount = new int[4];
public TextMeshProUGUI[] enemyLabel;
void Start()
{
enemyLabel[0].text = "" + enemyCount[0];
enemyLabel[1].text = "" + enemyCount[1];
enemyLabel[2].text = "" + enemyCount[2];
enemyLabel[3].text = "" + enemyCount[3];
}
public void AddEnemyCount(int num)
{
enemyCount[num] += 1;
enemyLabel[num].text = "" + enemyCount[num];
}
}



破壊数を増加させる
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class EnemyBot_A : EnemyBase
{
private void Start()
{
HP = 1;
}
// ★追加
public override void TakeDamage(int attackPower)
{
HP -= attackPower;
if (HP < 1)
{
Destroy(gameObject);
// ポイント(外部メソッドの呼び出し)
GameObject.Find("ShopManager").GetComponent<ShopManager>().AddEnemyCount(0); // 対応する番号を間違えないこと
}
}
}


ショップ・システムの作成②(敵の破壊数をカウントする)