The question is answered, right answer was accepted
Trying to destroy a bullet but it freezes! (JS)
Hey there, I've been trying to create a projectile which gets destroyed after a set amount of time. The problem I'm having is that the bullet freezes when it should be destroyed. I'm using prefabs to create the instances.
Here is the code I used, I apologise if not all of it is relevant:
BulletMaker.js
var bullet : Rigidbody;
var speed : float = 500.0f;
function Update () {
if (Input.GetMouseButtonDown(0))
{
var latestBullet = Instantiate(bullet, this.transform.position, transform.rotation);
latestBullet.AddRelativeForce(Vector3.forward * speed);
Destroy (latestBullet, 0.2f);
Debug.Log("Destroy");
}
}
Below is an image depicting what happens, though I understand that a still image doesn't really capture everything.
Answer by bubzy · Oct 03, 2015 at 04:42 AM
you need to Destroy(latestBullet.gameObject,0.2f);
because your code is just deleting the rigidbody from the prefab, while leaving everything else like the mesh renderer in place :)
Follow this Question
Related Questions
Destroy(GameObject) problem 1 Answer
rpc not working 0 Answers
Several instances destroyed when one is shot by player 0 Answers
Problem after 5 seconds destroy/deactivate component 1 Answer
Gameobject array 0 Answers