- Home /
how to increase or decrease ammo ?? but depending of ammo in inventory
so i want to make ammo script but i confused when increase or decrease ammo,
int currentAmmo; //i already make maksimum is 40 and minimum is 0
int ammoInventory; //and i make maksimum is 500 and minimum is 0
//so i want to add currentAmmo, but depending of ammoInventory
if (reloading)
{
if (currentAmmo <= 0 && ammoInventory > 40)
{
//i make simple increase and decrease
currentAmmo = 40;
ammoOnInventory -= 40;
//how can i make if currenAmmo = 15 and ammoInventory = 10
//currentAmmo should only be added 10
}
}
thanks
Comment
Best Answer
Answer by IvovdMarel · Dec 13, 2018 at 05:08 AM
if (reloading)
{
if (currentAmmo <= 0)
{
if (ammoInventory >= 40)
{
currentAmmo += 40;
ammoInventory -= 40;
} else
{
currentAmmo += ammoInventory;
ammoInventory = 0;
}
}
}