How do I set up a dictionary with sprites?

I have my dictionary definition for an inventory system:

public static Dictionary<int,string> inventoryNameDictionary = new Dictionary<int, string> ()

I tired changing it to:

public static Dictionary<int,Sprite> inventoryNameDictionary = new Dictionary<int, Sprite> ()

but I get a whole mess of errors. Is this the wrong way to do this. I want to show icons instead of just the name on my inventory buttons.

This is the link that to the tutorial series I was following - YouTube

So quickly looking at the code you posted it looks like your trying to use a Sprite in you GUILayout.Label calls on line 77/78. The method is expecting a Texture not a Sprite. Your Dictionary Definitions look fine. Have look at the reference for GUILabel.

You could update your Dictionaries to use textures instead of sprites.

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

public class inventory : MonoBehaviour {
	
	public Texture someTexture;
	
	public Dictionary<int, Texture> inventoryItems = new Dictionary<int, Texture> ();
	
	void Start () {
		inventoryItems.Add(0, someTexture);
	}
}

ERROR 1 Assets/Scripts/Pauser.cs(77,27): error CS1502: The best overloaded method match for `UnityEngine.GUILayout.Label(UnityEngine.Texture, params UnityEngine.GUILayoutOption)’ has some invalid arguments

ERROR 2 Assets/Scripts/Pauser.cs(77,27): error CS1503: Argument #1' cannot convert UnityEngine.Sprite’ expression to type `UnityEngine.Texture’

and that just repeates on line 78. I thought a label would work better than a button but i would prefer a guilayot.button

  using UnityEngine;
    using System.Collections;
    using System.Collections.Generic;
    
    public class Pauser : MonoBehaviour {
    	private bool paused = false;
    	public Texture2D image;
    	public Rect position;
    
    	public Sprite someSprite;
    	public Sprite someSprite2;
    
    	private bool inventoryWindowToggle = false;
    	private Rect inventoryWindowRect = new Rect(300,100,410,410);
    	
    	//private Dictionary
    	public Dictionary<int,Sprite> inventoryNameDictionary = new Dictionary<int, Sprite> ();
    //	{
    
    	void Start()
    	{
    		inventoryNameDictionary.Add (0, someSprite);
    		inventoryNameDictionary.Add (1, someSprite2);
    	}
    //		{0,string.Empty},
    //		{1,string.Empty}
    //		{2,string.Empty},
    //		{3,string.Empty},
    //		{4,string.Empty},
    //		{5,string.Empty},
    //		{6,string.Empty},
    //		{7,string.Empty},
    //		{8,string.Empty}
    //	};
    	
    	ItemClassScript itemObject = new ItemClassScript();
    	WeaponClassScript weaponObject = new WeaponClassScript();
    	
    	// Update is called once per frame
    	void Update () {
    		if(Input.GetKeyUp(KeyCode.P))
    		{
    			paused = !paused;
    		}
    		
    		if(paused)
    			Time.timeScale = 0;
    		else
    			Time.timeScale = 1;
    
    	
    
    	}
    
    	void OnGUI()
    	{
    		if (paused)
    			inventoryWindowToggle = GUI.Toggle (new Rect (800, 50, 100, 50), inventoryWindowToggle, "Inventory");
    		
    		if(inventoryWindowToggle)
    		{
    			inventoryWindowRect = GUI.Window(0,inventoryWindowRect, inventoryWindowMethod,"Inventory");
    		}
    	}
    	
    	void inventoryWindowMethod(int windowId)
    	{
    		if(HUDScript.hud.curOre == 1) 
    			inventoryNameDictionary [0] = itemObject.ore.icon;
    		inventoryNameDictionary [1] = weaponObject.sword1.icon;
    		//inventoryNameDictionary [2] = potion.name;
    		
    		
    		GUILayout.BeginArea(new Rect(10,50,390,400));
    		
    		GUILayout.BeginHorizontal ();
77    		GUILayout.Label(inventoryNameDictionary[0], GUILayout.Height (50));
78    		GUILayout.Label (inventoryNameDictionary[1], GUILayout.Height (50));
    //		GUILayout.Button (inventoryNameDictionary[2], GUILayout.Height (50));
    		GUILayout.EndHorizontal ();
    		
    //		GUILayout.BeginHorizontal ();
    //		GUILayout.Button (inventoryNameDictionary[3], GUILayout.Height (50));
    //		GUILayout.Button (inventoryNameDictionary[4], GUILayout.Height (50));
    //		GUILayout.Button (inventoryNameDictionary[5], GUILayout.Height (50));
    //		GUILayout.EndHorizontal ();
    //		
    //		GUILayout.BeginHorizontal ();
    //		GUILayout.Button (inventoryNameDictionary[6], GUILayout.Height (50));
    //		GUILayout.Button (inventoryNameDictionary[7], GUILayout.Height (50));
    //		GUILayout.Button (inventoryNameDictionary[8], GUILayout.Height (50));
    //		GUILayout.EndHorizontal ();
    		
    		GUILayout.EndArea ();
    		
    		
    		
    	}
    	
    	
    }