I want to make a crate that if I throw a grenade at it, and the grenade explodes, the crate will fall apart.
using UnityEngine;
using System.Collections;
public class PhysicsObject : MonoBehaviour {
public AudioClip landSound;
public AudioClip scrapeSound;
public float health;
float initHealth;
public HurtScript pain;
public GameObject Gibs;
void Start () {
initHealth = health;
}
void FixedUpdate()
{
if(health <= 0.01)
{
if(initHealth != 0)
{
GameObject TemporaryGrenadeHandler;
TemporaryGrenadeHandler = Instantiate(Gibs, gameObject.transform.position, gameObject.transform.rotation) as GameObject;
Destroy(gameObject);
}
}
}
void OnTriggerEnter(Collider other)
{
if(other.gameObject.tag == "Hurt")
{
pain = other.gameObject.GetComponent<HurtScript>();
if(initHealth != 0)
{
health -= pain.damage;
}
}
}
}
Can anyone help? it’s not depleting health, nor setting the object. I checked everything and made sure that the triggers indeed have the “Hurt” tag.