skip guns with no ammo left

similar to Quake 3 if i remember, when u scroll to change weapon and if that weapon has no ammo left, u automatically go to the next weapon with ammo available, my way doesn’t fully work so how do i go about this; example of my setup is like this:

	if (Input.GetAxis("Mouse ScrollWheel") < 0)
	{
		if(GunNumber == 4 && GunArray[0].GetComponent(GunScriptNetwork).ExtraAmmo > 0 &&
		GunArray[0].GetComponent(GunScriptNetwork).AmmoInCurrentClip > 0)
		{
			GunArray[GunNumber].GetComponent(GunScriptNetwork).enabled = false;
			GunArray[0].GetComponent(GunScriptNetwork).enabled = true;

			GunArray[GunNumber].GetComponentInChildren(MeshRenderer).enabled = false;
			GunArray[0].GetComponentInChildren(MeshRenderer).enabled = true;
			GunNumber = 0;
		}

as u can see im disabling just the mesh and a script to change guns, i cant disable the entire object otherwise i cant pick up ammo and such; in this case all the script is doing is when the array reaches the 5th and last gun as i scroll down, it changes to the 1st one. need help plz

I’m not sure what you’re doing with everything there, but I’d try something like

// imagine you have a class variable called CurrentGun

void Update()
{
	int LastGunUsed = CurrentGun;

	if (Input.GetAxis("Mouse ScrollWheel") < 0)
	{
		bool FoundLoadedGun = false;

		while (!FoundLoadedGun)
		{
			// Select the next gun in the array to examine
			int SelectedGun = CurrentGun+1;
			
			// If it's the last gun in the array, loop back to the starting one
			if (SelectedGun = GunArray.Length)
				SelectedGun = 0;

			// If the selected gun has ammo, set FoundLoadedGun = true and update CurrentGun 
			if (GunArray[SelectedGun].GetComponent(GunScriptNetwork).AmmoInCurrentClip > 0)
			{
				FoundLoadedGun = true;
				CurrentGun = SelectedGun;
			}

			// If we've run througfh the cycle so that we landed back on our CurrentGun again, we have no guns with ammo
			// you possibly want to default to knife/chainsaw/golf club/fists here/bad language (weapon 0??)
			if (SelectedGun == CurrentGun )
			{
				FoundLoadedGun = true;
				CurrentGun = 0;
			}

			// try the next gun
			SelectedGun++;
		}
	}

	GunArray[LastGunUsed].GetComponent(GunScriptNetwork).enabled = false;
	GunArray[LastGunUsed].GetComponentInChildren(MeshRenderer).enabled = false;

	GunArray[CurrentGun].GetComponent(GunScriptNetwork).enabled = true;
	GunArray[CurrentGun].GetComponentInChildren(MeshRenderer).enabled = true;
}