- Home /
Script Problems
How Can I make This code functional
var player : GameObject; var explosionRadius = 1; var explosionPower = 1; var explosionDamage = 100.0; var damage = 10; var enemyDamage : float=10f;
var explosionTime = 1.0;
function Start () {
var explosionPosition = transform.position;
var colliders : Collider[] = Physics.OverlapSphere (explosionPosition, explosionRadius);
for (var hit in colliders) {
if (!hit)
continue;
if (hit.rigidbody) {
hit.rigidbody.AddExplosionForce(explosionPower, explosionPosition, explosionRadius, 3.0);
var closestPoint = hit.rigidbody.ClosestPointOnBounds(explosionPosition);
var distance = Vector3.Distance(closestPoint, explosionPosition);
// The hit points we apply fall decrease with distance from the hit point
var hitPoints = 1.0 - Mathf.Clamp01(distance / explosionRadius);
hitPoints *= explosionDamage;
// Tell the rigidbody or any other script attached to the hit object
// how much damage is to be applied!
// I modified This part of the code.
hit.gameObject.player.SendMessageUpwards("ApplyDamage", hitPoints, SendMessageOptions.DontRequireReceiver);
hit.rigidbody.SendMessageUpwards("ApplyDamage", hitPoints, SendMessageOptions.DontRequireReceiver);
}
}
// stop emitting ?
if (particleEmitter) {
particleEmitter.emit = true;
yield WaitForSeconds(0.5);
particleEmitter.emit = false;
}
// destroy the explosion
Destroy (gameObject, explosionTime);
}
I get the error "Player is not a member of unity game object" Thanks In Advance!
Comment
Answer by DaveA · Feb 12, 2011 at 08:30 AM
Where you have
hit.gameObject.player
get rid of .player
but I want it to be able to do damage to the player without having a rigid body attached to the player, how would I do this?