2D weapon switching

Im currently trying to create a 2D game where the player can swap between 3 different guns, all with there own sprites. But whenever i try and use my code it just automatically sets all my sprites to active. Any help with be useful, thanks! I have the a Weapon game object with my different weapons inside, with this script on it.

public int selectedWeapon = 0;

// Start is called before the first frame update
void Start()
{
    SelectWeapon();

}

// Update is called once per frame
void Update()
{
    int previousSelectedWeapon = selectedWeapon;

    if (Input.GetAxis("Mouse ScrollWheel") > 0f)
    {
        if (selectedWeapon >= transform.childCount - 1)
            selectedWeapon = 0;
        else
            selectedWeapon++;
    }

    if (Input.GetAxis("Mouse ScrollWheel") < 0f)
    {
        if (selectedWeapon <= transform.childCount - 1)
            selectedWeapon = 0;
        else
            selectedWeapon--;
    }

    if (Input.GetKey(KeyCode.Alpha1))
    {
        selectedWeapon = 0;
    }

    if(Input.GetKey(KeyCode.Alpha2) && transform.childCount >= 2)
    {
        selectedWeapon = 1;
    }

    if(Input.GetKey(KeyCode.Alpha3) && transform.childCount >= 3)
    {
        selectedWeapon = 2;
    }

    if (previousSelectedWeapon != selectedWeapon)
        SelectWeapon();
}

void SelectWeapon()
{
    int i = 0;
    foreach (Transform weapon in transform)
    {
        if (1 == selectedWeapon)
            weapon.gameObject.SetActive(true);
        else
            weapon.gameObject.SetActive(false);
        i++;

        
    }
}

}

Set up the weapon sprites as children of GameObjects. You’ll turn off the gameobjects to turn of the weapons.

using UnityEngine;
    
public class EasyWeaponSwap : MonoBehaviour
{
    [SerializeField] private KeyCode[] weaponKeyCodes =
 { KeyCode.Alpha1, KeyCode.Alpha2, KeyCode.Alpha3, KeyCode.Alpha4 };
    [SerializeField] private GameObject[] weapons = null;//set in inspector
    [SerializeField] private int currentWeapon = -1;

void Start()
{
    if (weapons.Length > 0)
        DeactivateAllWeapons();
    else
        throw new System.Exception("You didn't set the Weapons array in the gun script.");

    currentWeapon = 0;

    SelectWeapon(currentWeapon);
}

void Update()
{
    float scroll = Input.GetAxis("Mouse ScrollWheel");
    if (scroll != 0)
    {
        if (scroll > 0)
            ScrollWeaponUp();
        else
            ScrollWeaponDown();
    }

    for (int i = 0; i < weaponKeyCodes.Length; ++i)        
        if (Input.GetKeyDown(weaponKeyCodes*))*

SelectWeapon(i);
}
private void DeactivateAllWeapons()
{
for (int i = 0; i < weapons.Length; ++i)
weapons*.SetActive(false);*
}
private void SelectWeapon(int weaponIndex)
{
weapons[currentWeapon].SetActive(false);
currentWeapon = weaponIndex;
weapons[currentWeapon].SetActive(true);
}
private void ScrollWeaponUp()
{
int nextWeapon;
if (currentWeapon == 0)
nextWeapon = weapons.Length - 1;
else
nextWeapon = currentWeapon + 1;
SelectWeapon(nextWeapon);
}
private void ScrollWeaponDown()
{
int nextWeapon;
if (currentWeapon == weapons.Length)
nextWeapon = 0;
else
nextWeapon = currentWeapon - 1;
SelectWeapon(nextWeapon);
}
}

The solution I propose is to change the sprite of a single weapon game object instead of making the game objects active / deactivate.

[System.Serializable]
public class Weapon
{
    public Sprite weaponSprite;
    public int weaponId;
}

public class WeaponController : MonoBehaviour
{
    // fills the list from the inspector by assigning id and sprite
    public List<Weapon> weaponList;

    // no need child game objects, assign in the inspector
    public GameObject weaponGMO; 

    private SpriteRenderer weaponSpriteRenderer;
    private int selectedWeaponId = 0;
    private int currentWeaponId = 0;

    public void Start()
    {
        weaponSpriteRenderer = weaponGMO.GetComponent<SpriteRenderer>(); 
        SelectWeapon();
    }

    public void Update()
    {
        if (Input.GetAxis("Mouse ScrollWheel") > 0f){
            selectedWeaponId++;
        }

        if (Input.GetAxis("Mouse ScrollWheel") < 0f){
            selectedWeaponId--;
        }

        if (Input.GetKey(KeyCode.Alpha1)){
            selectedWeaponId = 0;
        }

        if (Input.GetKey(KeyCode.Alpha2)){
            selectedWeaponId = 1;
        }

        if (Input.GetKey(KeyCode.Alpha3)){
            selectedWeaponId = 2;
        }

        if(currentWeaponId != selectedWeaponId){
            SelectWeapon();
        }
    }

    private void SelectWeapon()
    {
        // gets the corresponded Weapon instance from list according to the selectedWeaponId
        Weapon selectedWeapon = weaponList.Find(x => x.weaponId == selectedWeaponId);

        // if player press invalid button that does not correspond a weapon, 
        // the Find function will return null. Checks it.
        if(selectedWeapon != null)
        {
            // taa-daa! changes the sprite of the weapon by selection
            weaponSpriteRenderer.sprite = selectedWeapon.weaponSprite;
            currentWeaponId = selectedWeaponId;
        }
    }
}