TankのHPを表示する












TankHPの表示
using UnityEngine;
// ★追加
using TMPro;
public class TankHP : MonoBehaviour
{
public int HP;
// ★追加
public TextMeshProUGUI HPLabel;
private void Start()
{
HPLabel.text = "" + HP;
}
private void OnCollisionEnter(Collision collision)
{
if (collision.gameObject.CompareTag("EnemyShell"))
{
HP -= 1;
// ★追加
HPLabel.text = "" + HP;
if (HP < 1)
{
this.gameObject.SetActive(false);
}
}
}
}


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











TankHPの表示
using UnityEngine;
// ★追加
using TMPro;
public class TankHP : MonoBehaviour
{
public int HP;
// ★追加
public TextMeshProUGUI HPLabel;
private void Start()
{
HPLabel.text = "" + HP;
}
private void OnCollisionEnter(Collision collision)
{
if (collision.gameObject.CompareTag("EnemyShell"))
{
HP -= 1;
// ★追加
HPLabel.text = "" + HP;
if (HP < 1)
{
this.gameObject.SetActive(false);
}
}
}
}


TankのHPを表示する