I have this issue where my gun shoots using raycast and the particles that appear is basically just a simple detonator (cloud of smoke), the detonator (cloud of smoke) will destroy itself once it hits a collider (to prevent it to hit again anywhere else), but if it destroys itself, then it cannot be used again!
So my issue is I can shoot my weapon once, and it will work perfectly fine, and show the particles/cloud of smoke, however if i shoot it again, it wont show the particles/cloud of smoke because its been destroyed.
I get this error which I understand: NullReferenceException: The prefab you want to instantiate is null.
I know it means that the script cannot access the prefab because its destroyed, my question is how do I spawn another one after its destroyed?
This is the script for the actual detonator
// The reference to the explosion prefab
var explosion : GameObject;
function OnCollisionEnter (collision : Collision) {
// Instantiate explosion at the impact point and rotate the explosion
// so that the y-axis faces along the surface normal
var contact : ContactPoint = collision.contacts[0];
var rotation = Quaternion.FromToRotation(Vector3.up, contact.normal);
Instantiate (explosion, contact.point, rotation);
//variable for your particle prefab that you created and saved as a prefab.
//drag that particle prefab here in the inspector
// And kill our selves
Kill ();
}
function Kill () {
// Stop emitting particles in any children
var emitter : ParticleEmitter= GetComponentInChildren(ParticleEmitter);
if (emitter)
emitter.emit = false;
// Detach children - We do this to detach the trail rendererer which should be set up to auto destruct
transform.DetachChildren();
// Destroy the projectile
Destroy(gameObject);
}
Thanks in advance.