using UnityEngine;
using UnityEngine.UI;
public class OnCollision : MonoBehaviour
{
public GameObject explosion;
public GameObject bustedTank;
void OnCollisionEnter(Collision other)
{
if (other.gameObject.tag != null && other.gameObject.tag.Equals("q"))
{
Life life = other.gameObject.GetComponent<Life>();
life.subBlood(20);
GameObject p = GameObject.Find("Image");
Image imageShowBlood = p.GetComponent<Image>();
imageShowBlood.fillAmount = (life.bloods+0.0f)/100;
if (life.bloods <= 0)
{
Destroy(other.gameObject);
Instantiate(bustedTank, transform.position, transform.rotation);
}
}
if (other.gameObject.tag != null && other.gameObject.tag.Equals("e"))
{
Life life = other.gameObject.GetComponent<Life>();
life.subBlood(20);
GameObject p = GameObject.Find("Image");
Image imageShowBlood = p.GetComponent<Image>();
imageShowBlood.fillAmount = (life.bloods + 0.0f) / 100;
if (life.bloods <= 0)
{
Destroy(other.gameObject);
Instantiate(bustedTank, transform.position, transform.rotation);
}
}
Destroy(gameObject);
GameObject obj = Instantiate(explosion, transform.position, transform.rotation);
Destroy(obj, 1.5f);
}
}
using UnityEngine;
public class Life : MonoBehaviour {
public int bloods = 100;
public void subBlood(int value)///公開血量
{
bloods -= value;
}
}