So, this picks up from a previous question, but the person who helped me did not respond. Here is the lay out:
-
Each NPC has a Health Script(Health.cs)
-
A grenade prefab calls the exploGren.cs
-
In the exploGren.cs script a health class is declared, and the damage is applied.
No damage is being applied to any of the NPCs. Im assuming the problem is at line: 16, Vector3 grenadeOrigin. Also, how OverlapSphere works?
public class ExploGren : MonoBehaviour
{
public GameObject explosivo;//the explosive particle
private GameObject insta;// instatntiation of variables for explosion
private float timer = 0.0f;//zero time
private float timeTD = 5.0f;//time ot detonate
private int exploDamage = 50;//grenade damage
private float explosiveRadius = 5.0f;//radious of the explosive damage
Collider[] collidersInRange;
Vector3 grenadeOrigin; //<- Possible problem
Health damageByGrenadeExplosion;//decalre health
// Use this for initialization
void Start ()
{
grenadeOrigin = transform.position;
}
// Update is called once per frame
void Update ()
{
timer +=1 * Time.deltaTime;//start counting
if(timer >= timeTD)//if timer is equal to detonation, detonate
{
collidersInRange = Physics.OverlapSphere(grenadeOrigin, explosiveRadius);
insta = (GameObject)Instantiate(explosivo, transform.position, transform.rotation);//create the explosion at the grenades position
foreach(Collider col in collidersInRange)
{
damageByGrenadeExplosion = col.GetComponent<Health>();
if(damageByGrenadeExplosion != null)
damageByGrenadeExplosion.Damage(exploDamage);//<--problem is here.
}
//Destroy(insta, .70f);
}
}
}