プレーヤーにHPをつける

プレーヤーにHPをつける
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class TankHealth : MonoBehaviour
{
public GameObject effectPrefab1;
public 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);
}
}
}
}




BattleTank(基礎/全31回)
他のコースを見る
プレーヤーにHPをつける
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class TankHealth : MonoBehaviour
{
public GameObject effectPrefab1;
public 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をつける