Best way to handle a lot of variables

Ok so i have a gunapp, and there are a lot of different guns. I made a variable for every one. I don’t know if this is the best way. I have the new 4.6 UI, i want to make a button for every single one, and pressing one of them will set the image to one of them. What is the best way of like doing that.

What my idea was, was to make a function for every single variable, and set it for every one. Problem is would there would be a function for EVERY VARIABLE, and that is a lot of them.

Basically, i want to change the UI.Image to a specific variable out of a huge list. How would i pick one out like that? Or is there a better way without a vast list of variables?

Here is my script if it helps, i just started it

#pragma strict

var gunImage : UnityEngine.UI.Image;

var m4a4 : Sprite;
var m4a4_xray : Sprite;
var m4a4_modern_hunter : Sprite;
var m4a4_desert_storm : Sprite;
var m4a4_faded_zebra : Sprite;
var m4a4_jungle_tiger : Sprite;
var m4a4_bullet_rain : Sprite;
var m4a4_desert_strike : Sprite;
var m4a4_howl : Sprite;
var m4a4_asiimov : Sprite;
var m4a4_urban_ddpat : Sprite;
var m4a4_radiation_hazard : Sprite;
var m4a4_tornado : Sprite;
var m4a4_zirka

function Start () {
	gunImage.sprite = m4a4_xray;
}

function Update () {

}

Use an array or List.

im afraid I don’t use JS so my answer will be in c#

something like this may work for you

using UnityEngine;
using System.Collections;


public class NewBehaviourScript : MonoBehaviour {


	public Sprite[] guns = new Sprite[4];//adjust this value to match the number of guns

	enum _gunNames {m4a4,m4a4_xray,m4a4_modern_hunter,m4a4_desert_storm}; //of course fill this out as you wish


	public Sprite gunImage; //i couldnt work out the UnityEngine.UI.Image thing

	//this method will allow a bit easier reading but it does require that you populate the guns[] array with the textures that match the enum

	void Start () {
		gunImage = guns[_gunNames.m4a4_modern_hunter];
	}
	
	// Update is called once per frame
	void Update () {
	
	}
}

If you want more than one variable per weapon (I assume you also need damage, ammo capacity etc.) you can create a simple custom class for your guns.

public class Weapon {

     public var weaponName : String;
     public var AmmoMax : int;
     public var AmmoCur : int;
     public var sprite : Sprite;
}

You can create a new gun by code like this

Weapon newWeapon = new Weapon();

newWeapon.weaponName = "Desert Eagle";
newWeapon.ammoMax = 7;

You cna also make the class a Monobehavior so you can just add it as a script to an actual weapon object/prefab.

As for the functions, you could use an Array or List as suggested, or a Dictionary (C# only).