How to pick up bullets more efficiently? I have a bullet pickup script with a string and object with shooting script.
Everything occurs in shooting script: shooting raycasts, bullet count(each weapon has it’s own magazine size and bullet count). But I can’t increase it from the bullet pickup script because each time I change weapon, every other weapon is disabled.
E.g the pickup is meant meant for a pistol but I enabled rifle for now. I go to pickup loop through the weapons(I CANT LOOP THROUGH INACTIVE OBJECTS AND IT GIVES ME ERROR)
How can I iterate through inactive objects? Or how else to manage bullets?
public class BulletPickup : MonoBehaviour
{
public int bulletAmount = 10;
public string weaponForPickup;
GameObject weaponRoot;
private void Start()
{
weaponRoot = GameObject.FindGameObjectWithTag("WeaponRoot");
}
private void OnTriggerEnter(Collider other)
{
if (other.tag == "Player")
{
foreach (Transform weapon in weaponRoot.transform)
{
if (weapon.gameObject.GetComponent<ShootingScritpt>().GetWeaponType() == weaponForPickup)
{
weapon.gameObject.GetComponent<ShootingScritpt>().AddFoundBullets(bulletAmount);
}
}
Destroy(gameObject);
}
}
}