if (Input.GetKey(KeyCode.Space))
{
timer -= Time.deltaTime;
if (timer < 0)
{
Rigidbody bull = (Rigidbody)Instantiate(bullet, transform.position, transform.rotation);
bull.AddForce(Vector3.forward * 10f);
timer = 5f;
}
}
This has me stumped. Wondering why my timer isn’t resetting to 5 after I shoot?
Is there something wrong with my logic?
Thanks!
Okay, weird.
I found the problem.
if (timer < 0)
{
Rigidbody bull = (Rigidbody)Instantiate(bullet, transform.position, transform.rotation);
bull.AddForce(Vector3.forward * 10f);
timer = 5f;
}
Unity doesn’t read anything after:
bull.AddForce(Vector3.forward * 10f);
I changed it to:
{
timer = 5f;
Rigidbody bull = (Rigidbody)Instantiate(bullet, transform.position, transform.rotation);
bull.AddForce(Vector3.forward * 10f);
}
and now it works fine. Why is this?
Is it a bug? (I am using 5.3.1 because too lazy to update right now)