I’m making a FPS game, but reloading won’t work! I’m writing it with JavaScript
Can anyone help?
Code:
public var BulletPrefab : Transform;
public var BulletSpeed : float = 6000;
public var GunMuzzle : Transform;
public var ClipSize : float = 30;
public var Clip : float = 30;
public var ReloadTime : float = 2.0;
function Update ()
{
if (Input.GetButtonDown("Fire1"))
{
if (!BulletPrefab | !BulletSpeed )
{
Debug.Log("[shoot] Undefined Variables");
}
else
{
if (Clip >0)
{
var BulletSpawn = Instantiate (BulletPrefab,GunMuzzle.transform.position,Quaternion.identity);
BulletSpawn.rigidbody.AddForce(transform.forward * BulletSpeed );
Clip -= 1;
}
}
}
}
if (Clip < 1 )
{
Debug.Log("Reloading");
yield WaitForSeconds (ReloadTime);
Clip = ClipSize;
}