個別にダメージを判定できるようにする
個別ダメージ判定
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.SceneManagement;
using UnityEngine.UI;
public class TankHealth : MonoBehaviour
{
private int tankHP = 10;
public Text HPLabel;
public string sceneName;
void Start()
{
HPLabel.text = "" + tankHP;
}
private void OnCollisionEnter(Collision collision)
{
if(collision.gameObject.tag == "Shell")
{
tankHP -= 1;
HPLabel.text = "" + tankHP;
if(tankHP < 1)
{
this.gameObject.SetActive(false);
SceneManager.LoadScene(sceneName);
}
}
}
}
個別ダメージ判定
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.SceneManagement;
using UnityEngine.UI;
public class TankHealth : MonoBehaviour
{
private int tankHP = 10;
public Text HPLabel;
public string sceneName;
void Start()
{
HPLabel.text = "" + tankHP;
}
private void OnCollisionEnter(Collision collision)
{
if(collision.gameObject.tag == "Shell")
{
tankHP -= 1;
HPLabel.text = "" + tankHP;
if(tankHP < 1)
{
this.gameObject.SetActive(false);
SceneManager.LoadScene(sceneName);
}
}
}
}
個別にダメージを判定できるようにする