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.