- Home /
 
Explosion Damage not being applied.
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);
             }
 
 
     }
 }
 
              Answer by Irin · Jun 01, 2015 at 12:44 AM
Actually its being applied, i set the blast radius too small. for better effect, set it to 15.
Your answer
 
             Follow this Question
Related Questions
OverlapSphere not causing damage? - Solved 2 Answers
2D explosion that targets specific gameobjects 1 Answer
Raycast collider detector lags horribly? 2 Answers
Null reference and GetComponent 1 Answer