Anyone know why this doesn’t work? It initially waits the 3 seconds to fire, but after that it’s failing to listen to this line:
**LastFire = DateTime.Now.AddSeconds(firerate);**
After the initial 3 seconds, it proceeds to vomit rockets. As far as I can tell LastFire is not being assigned, any ideas?
public class MissleLauncher : MonoBehaviour
{
public Rigidbody projectile;
public float firerate = 3;
DateTime LastFire = DateTime.Now;
float speed = 1f;
// Use this for initialization
void Start ()
`` {
}
void Fire()
{
if (LastFire.AddSeconds(firerate) <= DateTime.Now)
{
Rigidbody instantiatedProjectile;
instantiatedProjectile = (Rigidbody)Instantiate(projectile, transform.position, transform.rotation);
instantiatedProjectile.velocity = transform.TransformDirection(new Vector3(0, 0, 100));
//instantiatedProjectile.position = transform.TransformDirection(transform.position + new Vector3(0, 0, 20));
Physics.IgnoreCollision(instantiatedProjectile.collider, transform.collider);
LastFire = DateTime.Now.AddSeconds(firerate);
}
}
// Update is called once per frame
void Update ()
{
}
So, I don’t have an explanation for this yet, but when I moved the DateTime assignment to the top of the Fire() block, it works like a charm. SO CONFUSED! If anyone knows what is going on here please let me know, I’d love to have my sanity back.