Hello I have a game where you shoot fireballs and have a little code that goes with it that doesn’t work, I want to destroy the Instantiated fireball after 5 seconds but when the fireball is Destroyed I gives an error saying “Missing reference exception The object of type ‘Transform’ has been destroyed but you are still trying to access it.
Your script should either check if it is null or you should not destroy the object.”
I don’t know what to do, I want it to be destroyed after 5 seconds. Heres the code for the object that creates the fireballs
#pragma strict
var fireball : Transform;
var timer = 0f;
function Update ()
{
var hit : RaycastHit;
if(Input.GetMouseButtonDown(0))
{
var fire = Instantiate(fireball, transform.position , Quaternion.identity);
fire.rigidbody.useGravity = true;
fire.rigidbody.AddForce(transform.forward * 1500);
fireball != null;
}
}
this doesn’t work, I even tried if(fireball == null)
{
fireball != null;
}
heres the code for my fireball:
#pragma strict
function Update () {
if(Input.GetMouseButtonDown(0))
{
Destroy(gameObject, 5);
gameObject != null;
}
}
please help
Thanks
_1