In this part of my script, there is a variable called colliders. A ray is cast to find the colliders and it finds all of them in a certain radius.
Some colliders have different scripts in them, but each of those different scripts share a variable called SystemHealth. How can I access that variable even though some colliders don’t have any scripts and some of the scripts have different names?
Another way to word the question: How can I find the variable SystemHealth inside of the colliders. Here is the important part of the script.
function Explode() {
var colliders : Collider[] = Physics.OverlapSphere (transform.position, radius);
for (var collider : Collider in colliders) {
var hit : RaycastHit;
if (Physics.Linecast(transform.position, collider.transform.position, hit)) {
if (hit.collider == collider) {
if (hit.rigidbody)
hit.rigidbody.AddExplosionForce(power - (power / hit.distance), transform.position, radius, 3.0);
}
}
}
}
Note that the script name is not SystemHealth. It's just a variable that may or may not be inside the colliders. I'll try it out but I think the javascript is wrong. Maybe I know how to fix it. Edit: Yeah I added in: print(hit.collider.gameObject.GetComponent(SystemHealth)); and it calls SystemHealth an unknown identifier.
– Doneyesoh lol then replace systemHealth with the script name > var health = hit.collider.gameObject.GetComponent(script > name).SystemHealth;
– KMKxJOEY1