here is my code i just need to fire only 3 bullets but i dont understand how to do it
public Transform firepoint;
public Transform firepoints;
public Transform Firepoint;
public GameObject bulletPrefab;
public GameObject RocketPrefab;
public GameObject GernadePrefab;
public GameObject LandMine;
private int currentBullets = 0;
private int totalbullets = 4;
public float BulletForce = 20f;
public float GernadeForce = 20f;
// Start is called before the first frame update
void Start()
{
}
// Update is called once per frame
void Update()
{
if (GameManager.Instance.isGameInPlay == true)
{
if (Input.GetKeyDown(KeyCode.LeftControl))
{
if (CarController.instance.CurrentWeapon == 1)
{
Shoot();
}
if (CarController.instance.CurrentWeapon == 2)
{
BulletShoot();
}
if (CarController.instance.CurrentWeapon == 3)
{
Gernade();
}
if (CarController.instance.CurrentWeapon == 4)
{
Landmine();
}
}
}
}
void BulletShoot()
{
if (currentBullets > 0)
{
foreach (var firepoint in firepoint)
{
GameObject bullet = Instantiate(bulletPrefab, firepoint.position, firepoint.rotation);
Rigidbody2D rb = bullet.GetComponent<Rigidbody2D>();
rb.AddForce(firepoint.up * BulletForce, ForceMode2D.Impulse);
}
}
else
{
currentBullets = totalbullets;
}
}
void Shoot()
{
GameObject bullet = Instantiate(RocketPrefab, firepoints.position, firepoints.rotation);
Rigidbody2D rb = bullet.GetComponent<Rigidbody2D>();
rb.AddForce(firepoints.up * BulletForce, ForceMode2D.Impulse);
}
void Gernade()
{
GameObject bullet = Instantiate(GernadePrefab, firepoints.position, firepoints.rotation);
Rigidbody2D rb = bullet.GetComponent<Rigidbody2D>();
rb.AddForce(firepoints.up * GernadeForce, ForceMode2D.Impulse);
}
void Landmine()
{
GameObject bullet = Instantiate(LandMine, Firepoint.position, Firepoint.rotation);
Rigidbody2D rb = bullet.GetComponent<Rigidbody2D>();
rb.AddForce(Firepoint.up * GernadeForce, ForceMode2D.Impulse);
}