Destructible Crate Problem
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.
Comment
Best Answer
Answer by O8PC · Feb 21, 2017 at 08:58 PM
I found out what happened. There was a position error, which I fixed. it's all good now .-.
Your answer
Follow this Question
Related Questions
How Do I make a 3D Numbered Padlock? 0 Answers
Airstrike in a area around the player 1 Answer
I'm having a few issues with (Catmull)Splines that i need help with. 1 Answer
Can't get raycast to mousePosition 0 Answers
How do i ajust the player height acording to the height of the roof in a first person game? 1 Answer