from the code I can see that you want to shoot every 10 seconds with range <= 10 as the condition. Instead of using extra memory making canShoot booleans, just do
var range : int;
var ReloadTime : float = 10;
InvokeRepeating ("Shoot", 0, ReloadTime );
// Reload time should be 10, that's a long time though
function Update() {
//whatever range caluclation you're performing
//I advise you use Vector3.sqrMagnitude instead of Vector3.Distance because the latter is more expensive
//I put range in Awake so that Shoot() can access it
}
function Shoot () : void {
if (range <=10) {
Instantiate(bullet, transform.position, Quaternion.identity);
}
else {return;}
}
↧