i cannot figure out why this code is not working. I am adding rate of fire to my instantiation. I want it to limit the rate of fire to 1 ball every 2 seconds. Right now it doesn't even shoot.
public var deathBall: Rigidbody;
public var ballSpeed: float = 25.0;
private var reloadTime: float;
private var canShoot: boolean;
function Start()
{
reloadTime = 0.0;
canShoot = true;
}
function Update ()
{
if(canShoot == true)
{
MouseClick();
}
reloadTime += Time.deltaTime;
if(reloadTime >= 2.0)
{
canShoot = true;
reloadTime = 0.0;
}
if(reloadTime <= 2.0)
{
canShoot = false;
}
}
function MouseClick()
{
if(Input.GetButtonDown("Fire1"))
{
Instantiate();
canShoot = false;
}
}
function Instantiate()
{
var newBall : Rigidbody = Instantiate(deathBall, transform.position, transform.rotation);
newBall.velocity = transform.TransformDirection(Vector3(0, 0, ballSpeed));
Physics.IgnoreCollision(newBall.collider, transform.root.collider);
}