Hi Guys,
I am just trying to apply an AddExplosionForce() to an object. I copied the code direct from the reference matierials.
But I am getting an error saying hit.rigidbody, rigidbody is not a member of Collider. Ok, but then what do I do, and why is this in the reference material?
Unity’s Code
var radius = 5.0;
var power = 10.0;
function Start () {
// Applies an explosion force to all nearby rigidbodies
var explosionPos : Vector3 = transform.position;
var colliders : Collider[] = Physics.OverlapSphere (explosionPos, radius);
for (var hit : Collider in colliders) {
if (!hit)
continue;
if (hit.rigidbody)
hit.rigidbody.AddExplosionForce(power, explosionPos, radius, 3.0);
}
}
My Code
function blowUpGrenade()
{
print("+++++++++blowing up greande++++++++++++++");
var radius = 5.0;
var power = 10.0;
var explosionPos : Vector3 = transform.position;
var colliders : Collider[] = Physics.OverlapSphere (explosionPos, radius);
for (var hit : Collider in colliders)
{
if (!hit)
{
print("!hit");
continue;
}
if (hit.rigidbody)
{
hit.rigidbody.AddExplosionForce(power, explosionPos, radius, 3.0);
print("hit.rigidbody " + hit.rigidBody);
}
}
}
The error occurs on line 19.