top of page
Search

Bullet count and reload

  • Writer: Keshav Batra
    Keshav Batra
  • Mar 18, 2021
  • 1 min read

What I have here is a bullet recount and a reload function that automatically refills the ammo an unlimited amount of time. I just need to program it to when my ammo runs out and when I touch the ammo, it doesn't refill an unlimited amount of time.

Bullet Pickup

{

public int BulletCount = 50;

//anything that has parentheses, a void, and brackets is a function

//other means whatever type of variable you have eg. Collider

private void OnTriggerEnter(Collider other)

{

if (other.gameObject.GetComponent<Player>())

{

GameObject weaponHolder = GameObject.Find("WeaponHolder");

//To go through all the children that the weopon holder has

for (int i = 0; i < weaponHolder.transform.childCount; i++)

{

if (weaponHolder.transform.GetChild(i).gameObject.activeSelf)

{

weaponHolder.transform.GetChild(i).GetComponent<Gun>().currentAmmo += BulletCount;

weaponHolder.transform.GetChild(i).GetComponent<Gun>().ammotext.SetText("Ammo: " + weaponHolder.transform.GetChild(i).GetComponent<Gun>().currentAmmo);

}

}

}

}



}


 
 
 

Comments


bottom of page