Object.Destroy not destroying object

Hello,

I’m new to Unity (been using it for maybe a week or so) and a novice programmer (though I’d like to think I know the basics pretty well). I’ve been teaching myself Java through trial-and-error, the Unity forums/documentation, and reverse engineering through the scripts people have been generous enough to use/reference.

My problem: I have looked up Object.Destroy(). As I understand, this is the function that is used to despawn/kill an object from the scene. When I use it, all it seems to do is make the bullet stop in mid-air.

// variable declaration
var rocket : Rigidbody;
var speed = 100.0;

function Update () 
{
	// firing function
	TurretFire ();
}

function TurretFire ()
{
	// when user pushes the spacebar
	if (Input.GetKeyDown ("space"))
	{
		// confirm that the spacebar has been pressed
		print ("Space is pressed.");

		// instances the rocket mesh
		var rocketClone : Rigidbody = Instantiate(rocket, transform.position, transform.rotation);
		// gives the rocket mesh a velocity and fires
		rocketClone.velocity = transform.forward * speed * -1;
		// destroys the rocket after 1 second
		Destroy (rocketClone, 1.0);
	}
}

I theorize it just deletes the Rididbody thus getting rid of the physics aspect of the bullet. Therefore, I tried
Destory (GameObject, 1.0); or Destroy(this, 1.0);
in place of
Destroy (rocketClone, 1.0);
and it takes away my ability to fire rockets all together as well as failing to remove the prefab rocket from the scene.

I’m confident it’s just a small thing I’m missing, but I can’t seem to figure it out. Any thoughts on the matter will be helpful.

Thanks,

-S

I think I figured it out.

replaced
Destroy(rocketClone, 1.0);
with
Destroy(rocketClone.gameObject, 1.0);

This seems to work. If that is really the solution or if you have a different idea, feel free to reply :slight_smile:

-S

in the projectiles of my game i usualy type

Destroy (gameObject, 4);

its been working too… but i cant be sure of whats the right way to do it because im much more novice than you are =D

@Warp boy2
I used a 1 second timer so I could physically see the projectiles get deleted from memory. Once I was sure they were, I’d modify the timers and speed.

-S

oh, got it o/