As the title says; I'm trying to make a gun script, I have the gun shooting as I wanted, but the cloned rigidbodies stick around, clogging up the game. How would I make them disappear after a set amount of time?
var lifeTime = 1.0;
function Awake () { Destroy (gameObject, lifeTime); }
Here you go. Next time use the search function because that has been answered several times.
var destroyTime : Int; // This is the time in seconds
function Start(){
yield WaitForSeconds(destroyTime);
Destroy(gameObject);
}
// attach the script to the game object that is supposed to disappear. Good Luck =)
public class Dissapear : MonoBehaviour {
int lifeTime = 10;
public override void Start()
{
StartCoroutine(WaitThenDie());
}
IEnumerator WaitThenDie()
{
yield return new WaitForSeconds(lifeTime);
Destroy(gameObject);
}
}