- Home /
Finding a certain variable is failing
This grenade script sends rays out to objects in a certain radius. If in one of the colliders is a script called HitBoxUpperArm, then it sets the variable CurrentHealth to 0. I think the problem is that the script is crashing because not all colliders it hits has that script in it. What should I do? Here is the script.
 function Explode() {
  
     var colliders : Collider[] = Physics.OverlapSphere (transform.position, radius);
         for (var collider : Collider in colliders) {
             //if (collider.tag == "brick" || collider.tag == "player") {
             //colliders.gameObject.GetComponent(SystemHealth).GetComponent(Ragdoll).Ragdoll = true; //Find the torso somehow then make it ragdoll
                 var hit : RaycastHit;
                 if (Physics.Linecast(transform.position, collider.transform.position, hit)) {
                     if (hit.collider == collider) {
                     hit.collider.GetComponent(HitBoxUpperArm).CurrentHealth = 0;
                         if (hit.rigidbody)
                             hit.rigidbody.AddExplosionForce(power - (power / hit.distance), transform.position, radius, 3.0);
                 }
             }
         }
     //}
 }
               Comment
              
 
               
              Your answer
 
 
              koobas.hobune.stream
koobas.hobune.stream 
                       
                
                       
			     
			 
                