I need help with making a projectile disappear after x seconds have passed, but I have no clue how to set a lifespan, any help?
Here's what I tried but nothing worked (it's compiled attempts from other tutorials I've seen).
using UnityEngine;
using System.Collections;
using System;
public class Projectile : MonoBehaviour {
public float ProjectileSpeed;
protected float mLifeSpan;
public float lifeSpan{get{return mLifeSpan;}}
// Use this for initialization
void Start () {
mLifeSpan = 1.0f;
}
// Update is called once per frame
void Update ()
{
float amtToMove = ProjectileSpeed * Time.deltaTime;
transform.Translate(Vector3.forward * amtToMove);
}
protected IEnumerator kill()
{
yield return new WaitForSeconds(mLifeSpan);
Destroy(gameObject);
}
}
Any tips?