Unity UI dropdown List remove duplicated values

Add an directive

using System.Collections.Generic;

Create an list of strings called scannedNames

private List<string> scannedNames;

Then initiate the List in Start()

scannedNames = new List<string>();

Then When the Discovered Event is called, new name and peripheralID is added to the function.


        private void DiscoveredPeripheralAction(string peripheralId, string name)
        {
            if (showScanData)
            {
                 //Add logic that check if the new name is already contained in the scannedNames
                    if(scannedNames.Contains(name))
                    {
                              //if contains do not add to list
                    } else
                    {
                 //if do not contain add the name and peripheralID to the Dropdown list   
                        Dropdown.OptionData list = new Dropdown.OptionData(name + "," + peripheralId);
                        DevicesNames.options.Add(list);
                        
                        //Also add the name to the scannedNames
                        scannedNames.Add(name);
                    }
            }           
            DevicesNames.RefreshShownValue();
        }