using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class TankHealth : MonoBehaviour
{
public GameObject effectPrefab1;
public GameObject effectPrefab2;
public int tankHP;
private void OnCollisionEnter(Collision collision)
{
if (collision.gameObject.tag == "EnemyShell")
{
tankHP -= 1;
Destroy(collision.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);
// (ポイント)
// Tankの中の全ての子供にRigidbodyを追加する。
foreach (Transform child in transform)
{
if (child.GetComponent<Rigidbody>() == null)
{
child.gameObject.AddComponent<BoxCollider>();
child.gameObject.AddComponent<Rigidbody>();
}
}
}
}
}
}