var bullet = Instantiate(Prefab, gameObject.Find(“SpawnpointB”).transform.position, Quaternion.identity);
bullet.rigidbody.AddForce(transform.forward * 1000);
savedTime = seconds;
}
There is more code n stuff, but I have an error that says it was expecting a ) not and =
I messed around and found the issue lies in
if(seconds=savedTime)
How do I fix this?
Thanks.
“=” is assignment. “==” is comparison. Note that if you’re running that in Update and the values are based on time there is a very good change the 2 will never equal each other exactly.
= does the same thing it did before, which is spit abunch of bullets.
<= makes it so it doesn’t shoot anything
== makes it so it doesn’t shoot anything.
=/
hmm.
Use the first, only need is use Time.time to control the bullets shooting per time.
if(seconds > savedTime * Time.time)
or :
function Fire () { if (bulletsLeft == 0)
return;
// If there is more than one bullet between the last and this frame
// Reset the nextFireTime
if (Time.time - fireRate > nextFireTime)
nextFireTime = Time.time - Time.deltaTime;
// Keep firing until we used up the fire time
while( nextFireTime < Time.time bulletsLeft != 0) {
FireOneShot();
nextFireTime += fireRate;
}
}
function Update (){
if (Input.GetKey(KeyCode.F))
{
Fire ();
}
}
function Fire () {
if (bulletsLeft == 0)
return;
// If there is more than one bullet between the last and this frame
// Reset the nextFireTime
if (Time.time - fireRate > nextFireTime)
nextFireTime = Time.time - Time.deltaTime;
// Keep firing until we used up the fire time
while( nextFireTime < Time.time bulletsLeft != 0)
{
FireOneShot();
nextFireTime += fireRate;
}
}
function FireOneShot()
{
var bullet = Instantiate(Prefab, gameObject.Find("SpawnpointC").transform.position, Quaternion.identity);
bullet.rigidbody.AddForce(transform.forward * 1000);
}