In this script I need to find the distance between the gameObject and the collider it’s hitting if it’s inside the radius.
#pragma strict
var wake : boolean;
var power : float = 1500;
var damage : int = 1;
var radius : float = 5;
var explodeSound : AudioClip;
function Start () {
yield WaitForSeconds (5);
wake = true;
}
function Update () {
if(wake == true) {
Explode();
wake = false;
Destroy(gameObject);
}
}
function Explode() {
var colliders : Collider[] = Physics.OverlapSphere (transform.position, radius);
for (var collider : Collider in colliders) {
//if (collider.tag == "brick" || collider.tag == "player") {
var hit : RaycastHit;
if (Physics.Linecast(transform.position, collider.transform.position, hit)) {
if (hit.collider == collider) {
if (hit.rigidbody)
hit.rigidbody.AddExplosionForce(power, transform.position, radius, 3.0);
}
}
}
//}
}