Switching the index of a GameObject Array type?

Hi, I made more than a weapon in Unity, but now I need something to switch the

public GameObject inventory;

But later, the compiler saied I can’t use integer to switch the index of a gameObject Array.

I need to set active by integer the gameObject stored in a slot (1,2,3 etc).

Moreover the weapon should be changable by holding E, and they are:

1 = Melee, 2 = Pistols, 3 = Shotguns etc Like a fps arena… but the question is just for the gameObject array use.

Some help? Thanks! :slight_smile:

void ChangeWeapon()
{
foreach ( GameObject weapon in inInventory)
{
weapon.setActive(false);
}
inInventory[indexOfTheWeapon].setActive(true);
}

During this time I modified the code: I used enums, so now it works!
The only problem I don’t know how active the wanted slot, deactivating the other ones.

using System.Collections;
using System.Collections.Generic;
using UnityEngine;

public class WeaponSelection : MonoBehaviour {

    public GameObject[] inInventory = new GameObject[(int)INVENTORY_Melee.SlotCount];
    private GameObject activeWeapon;

    public enum INVENTORY_Melee
    {   
        Empty,
        Hammer,
        SlotCount
    }
    public enum INVENTORY_Guns
    {   
        Empty,
        NailGun,
        RevolverM_500,
        SlotCount
    }
    public enum INVENTORY_ShotGuns
    {
        Empty,
        SlotCount
    }
    public enum INVENTORY_MachineGuns
    {
        Empty,
        SlotCount
    }
    public enum INVENTORY_Explosives
    {
        Empty,
        SlotCount
    }
    public enum INVENTORY_Rifles
    {
        Empty,
        SlotCount
    }

    // Use this for initialization
    void Start () {
		
	}
	
	// Update is called once per frame
	void Update () {

    if (Input.anyKeyDown) {
            switch (Input.inputString)
            {
                case "0":
                    break;

                case "1":
                    GameObject activeMelee = inInventory[(int)INVENTORY_Melee.Hammer - 1];
                    activeWeapon = activeMelee;
                    break;

                case "2":
                    GameObject activeGun = inInventory[(int)INVENTORY_Guns.NailGun];
                    activeWeapon = activeGun;
                    break;

                case "3":
                    GameObject activeShotguns = inInventory[(int)INVENTORY_ShotGuns.Empty];
                    break;

                case "4":
                    GameObject activeMachineGuns = inInventory[(int)INVENTORY_MachineGuns.Empty];
                    break;

                case "5":
                    GameObject activeExplosives = inInventory[(int)INVENTORY_Explosives.Empty];
                    break;

                case "6":
                    GameObject activeRifles = inInventory[(int)INVENTORY_Rifles.Empty];
                    break;

                default:
                    break;
            }
        }
    }
}

I tried using gameObject.setActive(bool), but (again, )I need something which I can set active the gameobject in the slot I selected, setting not-active the other ones.

Just this for now.