Unity c# indexoutofrangeexception: array index is out of range

Trying to assign 3 values to a array.

public string[] weaponList = new string[3]; 

the rest is inside start()

weaponList[0] = "Pistol";
weaponList[1] = "SMG";
weaponList[2] = "Shotgun";

You should set weaponList = new string[3]; inside of start, not globally.

public string[] weaponList;
 
void Start(){
    weaponList = new string[3]; 
    weaponList[0] = "Pistol";
    weaponList[1] = "SMG";
    weaponList[2] = "Shotgun";
}