I am trying to remove an bullet after a set amount of time but all i get is the error saying it cant delete it due to data loss.
i am using the code
if (timer >= 4)
{
Destroy(Fireball.gameObject);
}
is there a way to remove the bullet that was fired after the set amount of time.
Based upon your confirmation that Fireball is a prefab, I think the problem is that you’re attempting to use the prefab directly.
In general, your code should be something like this:
// Inside the class - local variable, public access
public GameObject Fireball; // In the editor window, drop the Fireball prefab to this
// In a method ...
var fireballInstance = Instantiate(this.Fireball);
//Later, when you're done with it and want it gone
Destroy(fireballInstance);
You can’t destroy the prefab - and you shouldn’t be trying to use a prefab directly. If you placed it in your scene - so that it’s an instance, be sure to drag the Instance (from the scene graph) to the script reference, not the Prefab (from the project explorer) to the script reference.
AutoDestroy.js :
var ExpireTime : float;
function Start(){
yield WaitForSeconds(ExpireTime);
{
Destroy(gameObject);
}
}