Inventory Help?

This is the code I have right now…

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

public class Inventory : MonoBehaviour {

    public List<GameObject> slots = new List<GameObject>();
    public List<Dart> darts = new List<Dart>();
    public GameObject toolTip;
  
    private GameObject slot;
    private int x = -80;
    private int y = 110;
    private DartDatabase database;

    void Start () {
        int slotAmount = 0;

        database = GameObject.FindGameObjectWithTag("Game Master").GetComponent<DartDatabase>();

        slot = Resources.Load<GameObject>("Prefabs/Slot Prefab");
        for(int a = 0; a < 5; a++){
            for(int b = 0; b < 4; b++){
                GameObject thisSlot = (GameObject)Instantiate(slot);
                thisSlot.GetComponent<SlotScript>().slotNumber = slotAmount;
                slots.Add(thisSlot);
                darts.Add(new Dart());
                thisSlot.transform.parent = this.gameObject.transform;
                thisSlot.name = "Slot" + a + "." + b;
                thisSlot.GetComponent<RectTransform>().localPosition = new Vector3(x, y, 0);
                x = x + 55;
                if(b == 3){
                    x = - 80;
                    y = y - 55;
                }
                slotAmount ++;
            }
        }

        AddDart(0);
        AddDart(0);
        AddDart(0);
        AddDart(0);
        AddDart(0);
        AddDart(1);
    }

    public void AddDart(int id){ //The id is how I seperate the different types of darts.
        for(int i = 0; i < database.darts.Count; i++){
            if(database.darts[i].dartID == id){
                Dart dart = database.darts[i];
                AddDartAtEmptySlot(dart);
                break;
            }
        }
    }

    public void AddDartAtEmptySlot(Dart dart){
        for(int i = 0; i < darts.Count; i++){
            if(darts[i].dartName == null){
                darts[i] = dart;
                break;
            }
        }
    }

What I’m trying to accomplish is the GUI for my characters inventory of darts. The problem I’m having is that this displays EVERY SINGLE dart in the inventory (replicas included). I don’t want duplicates to be displayed. I only want to display one of each type of dart. So…I tried using this… (the following replaces lines 23 through 39 of the original code).

int slotAmount = 0;
        Dart lastDart = new Dart();
        foreach(Dart dart in playersDarts){
            if(dart.dartType != lastDart.dartType){
                GameObject thisSlot = (GameObject)Instantiate(slot);
                thisSlot.GetComponent<SlotScript>().slotNumber = slotAmount;
                dartSlots.Add(thisSlot);
                thisSlot.transform.parent = transform.GetChild(7).gameObject.transform;
                thisSlot.name = "Slot" + slotAmount;
                dartSlotAmount ++;
                lasDart = dart;
            }
        }

This helped a little…but it’s only drawing (in the GUI) the first 2 darts (which are the same). It doesn’t cycle through all 6 darts in the players inventory.

The player’s inventory contains 6 darts. The first 5 are the same and the sixth is different.

…never mind…I figured it out myself. :roll_eyes: Gotta love it when you figure out a problem RIGHT after you ask for help. Solution on lines 11 and 12.

        int slotAmount = 0;
        Dart lastDart = new Dart();
        foreach(Dart dart in playersDarts){
            if(dart.dartType != lastDart.dartType){
                GameObject thisSlot = (GameObject)Instantiate(slot);
                thisSlot.GetComponent<SlotScript>().slotNumber = slotAmount;
                dartSlots.Add(thisSlot);
                thisSlot.transform.parent = transform.GetChild(7).gameObject.transform;
                thisSlot.name = "Slot" + slotAmount;
            }
                dartSlotAmount ++; //This line had to be moved outside of the if statement.
                lasDart = dart; //So did this line.
        }