プレーヤーにHPをつける

プレーヤーHP
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class TankHealth : MonoBehaviour
{
[SerializeField]
private GameObject effectPrefab1;
[SerializeField]
private GameObject effectPrefab2;
public int tankHP;
private void OnTriggerEnter(Collider other)
{
// もしもぶつかってきた相手のTagが”EnemyShell”であったならば(条件)
if (other.gameObject.tag == "EnemyShell")
{
// HPを1ずつ減少させる。
tankHP -= 1;
// ぶつかってきた相手方(敵の砲弾)を破壊する。
Destroy(other.gameObject);
if (tankHP > 0)
{
GameObject effect1 = Instantiate(effectPrefab1, transform.position, Quaternion.identity);
Destroy(effect1, 1.0f);
}
else
{
GameObject effect2 = Instantiate(effectPrefab2, transform.position, Quaternion.identity);
Destroy(effect2, 1.0f);
// プレーヤーを破壊する。
Destroy(gameObject);
}
}
}
}




【2020版】BattleTank(基礎/全35回)
他のコースを見る
プレーヤーHP
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class TankHealth : MonoBehaviour
{
[SerializeField]
private GameObject effectPrefab1;
[SerializeField]
private GameObject effectPrefab2;
public int tankHP;
private void OnTriggerEnter(Collider other)
{
// もしもぶつかってきた相手のTagが”EnemyShell”であったならば(条件)
if (other.gameObject.tag == "EnemyShell")
{
// HPを1ずつ減少させる。
tankHP -= 1;
// ぶつかってきた相手方(敵の砲弾)を破壊する。
Destroy(other.gameObject);
if (tankHP > 0)
{
GameObject effect1 = Instantiate(effectPrefab1, transform.position, Quaternion.identity);
Destroy(effect1, 1.0f);
}
else
{
GameObject effect2 = Instantiate(effectPrefab2, transform.position, Quaternion.identity);
Destroy(effect2, 1.0f);
// プレーヤーを破壊する。
Destroy(gameObject);
}
}
}
}




プレーヤーにHPをつける