I have a weapon switching system that is very simple, I have a list of weapons and I can cycle through them using my scroll wheel
int previousSelectedWeapon = selectedWeapon;
if(Input.GetAxis("Mouse ScrollWheel") > 0f)
{
if(selectedWeapon - 1 >= 0)
{
selectedWeapon--;
}
else
{
selectedWeapon = maxWeapons;
}
}
if(Input.GetAxis("Mouse ScrollWheel") < 0f)
{
if(selectedWeapon + 1 <= maxWeapons)
{
selectedWeapon++;
}
else
{
selectedWeapon = 0;
}
}
if(previousSelectedWeapon != selectedWeapon)
{
SelectWeapon();
}
}
public void SelectWeapon()
{
int i = 0;
foreach (Transform weapon in transform)
{
if (i == selectedWeapon)
{
weapon.gameObject.SetActive(true);
}
else
{
weapon.gameObject.SetActive(false);
}
i++;
}
}
However this is not exactly what I'm looking for, I want to be able to have a maximum of x weapons currently equipped and I can only cycle through them.
Let's say I have 1 weapon I can pick up another weapon, but if I have the max amount of weapons equipped, I want my currently selected weapon to be replaced by the weapon I'm picking up