I’m working on an FPS and one of the aspects is a Grenade or Exploding. This is the script that controls the explosion and it gives me an error that says
#pragma strict
var explosionTime : float = 2;
var explosionRadis : float = 10.0;
var explosionPower : float = 2000.0;
function Start () {
// Find Anything that can have collision
var colliders : Collider[] = Physics.OverlapSphere(transform.position, explosionRadis);
// Apply a Force to any Physics Objects near bye
for(var hit in colliders) {
if(hit.rigidbody) {
hit.rigidbody.AddExplosionForce(explosionPower,transform.position, explosionRadis);
}
// Particle Emitter
if(particleEmitter){
particleEmitter.emit = true; // Turn On Particles
yield WaitForSeconds(0.5); // Sets time Delay
particleEmitter.emit = false; // Turn off Particles
}
}
// Destroys the Explosion After 1 Second
Destroy(gameObject, explosionTime);
}
Explosion JS
#pragma strict
var explosion : GameObject;
function OnCollisionEnter(collision : Collision) {
// Find out where the bullet is contact
var onContact : ContactPoint = collision.contacts[0];
// Find the Rotation of the Object and the contact Normal
var rotation = Quaternion.FromToRotation( Vector3.up, onContact.normal );
// Create the Explosion
var instantiateExplosion : GameObject = Instantiate( explosion, onContact.point, rotation);
// Destroy the Bullet
Destroy(gameObject);
}