- Home /
Question by
Didymos · Jan 13, 2011 at 04:41 AM ·
javascriptprojectiledisable
How do I make a projectile disappear seconds after it is fired? The projectile stays within the game forever. How do I disable it, 3 seconds after it has been fired?
var bullitPrefab:Transform;
function Update ()
{
if(Input.GetKeyDown("e"))
{
var bullit = Instantiate(bullitPrefab, GameObject.Find("SummonEscape_Spawn").transform.position, Quaternion.identity);
bullit.rigidbody.AddForce(transform.forward * 100);
}
}
Comment
Best Answer
Answer by Justin Warner · Jan 13, 2011 at 04:55 AM
function Update() {
if(Input.GetKeyDown("e"))
{
spawnBullet(grenade);
}
} var grenade; spawnBullet() { Instantiate(grenade, GameObject.Find("SummonEscape_Spawn").transform.position, Quaternion.identity);
grenade.rigidbody.AddForce(transform.forward*100);
yield WaitForSeconds(3);
Destroy(grenade);
}
Not tested, but should work.
Does it spawn an actual gernade or is that part of the coding which is used in the script?
Thanks for the help. I think this is going to be best answer.
Wait I read over the script and it makes so much sense to me. Thanks for the help. I will try out the script.
Your answer
![](https://koobas.hobune.stream/wayback/20220613095220im_/https://answers.unity.com/themes/thub/images/avi.jpg)