Checking values in list not working quite right.

I am trying to make two buttons which will each create a different type of player. I’ve set it so pressing each button changes a value in my File Manager object with my FileManager script attached, basically this is my game manager but for other reasons it’s not named so. (UPDATE) ANYWAYS I press any button, run through the on-screen steps of making myself a new player which will be customized later. It adds a Player/class/ player/name of new class instance/, and pushes it to Players/list of all players so far/ with a name, type and ini/just a name for a value/ value already set for that specific class instance. Now pressing any button and creating ANOTHER player works all well and good, and if I try to type in one with the same name(let’s call this name A), it won’t accept it, thus keeping each player unique. BUT, if I press any button, and try to name one with a different name(say B for instance, and then make ANOTHER with the same name as before(A), it just accepts it. Here’s the code for my File Manager

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

public class FileManager : MonoBehaviour
{
    public class Relation
    {
        public string Name;
        public int Level;
        public int Precedence;
    }

    public class Player
    {
        public string Name;
        public int Type;
        public Relation Relation;
        public int Initiative;
    }

    public Text nameText;

    public List<Player> Players = new List<Player>();

    public Player player = new Player();

    public string playerName;

    public string playerText;

    public string buttonPressed;

    public int playerType;

    public int playerIni;

    public bool uniqueName;

    public bool preFinished;

    public bool finished;

    public bool naming;

    public bool enterData;

    public bool relations;

    public bool enteredC;

    public bool redEffect;

    public GameObject newType1;

    public GameObject newType2;

    public GameObject continueButton;

    public void Restart(bool b)
    {
        if (b == false)
        {
            player.Initiative = 0;
        }
        else if (b == true)
        {
            Int32.TryParse(playerText, out playerIni);
            player.Initiative = playerIni;
        }
        Players.Add(player);
        enterData = false;
        enteredC = false;
        playerName = "";
        playerText = "";
        buttonPressed = "";
        playerIni = 0;
        nameText.text = "Add New Player";
        newType1.GetComponent<Button>().enabled = true;
        newType2.GetComponent<Button>().enabled = true;
        if (Players.Count >= 1)
        {
            continueButton.GetComponent<Button>().enabled = true;
        }
    }
    
    void Start()
    {
        continueButton.GetComponent<Button>().enabled = false;
        buttonPressed = "";
    }

    void Update()
    {
        if (buttonPressed != "")
        {
            if (buttonPressed == "New Type 1")
            {
                playerType = 0;
            }
            if (buttonPressed == "New Type 2")
            {
                playerType = 1;
            }
            newType1.GetComponent<Button>().enabled = false;
            newType2.GetComponent<Button>().enabled = false;
            nameText.text = "Enter Name";
            naming = true;
            buttonPressed = "";
        }
        if (naming == true)
        {
            foreach (char c in Input.inputString)
            {
                if (c == '\b')
                {
                    if (playerName.Length != 0)
                    {
                        playerName = playerName.Substring(0, playerName.Length - 1);
                    }
                }
                else if (c == '

’ || c == ‘\r’)
{
uniqueName = true;
foreach (Player p in Players)
{
if (p.Name == playerName)
{
uniqueName = false;
}
}
if (uniqueName == true)
{
nameText.text = “Initiative [0-10] (To Skip, Press Space)”;
enteredC = false;
player.Name = playerName;
player.Type = playerType;
enterData = true;
naming = false;
}
else if (uniqueName == false)
{
enteredC = false;
nameText.text = “Please Choose A Unique Name”;
playerName = “”;
}
}
else
{
playerName += c;
if (enteredC == false)
{
enteredC = true;
}
}
}
if (enteredC == true)
{
nameText.text = playerName;
}
}
else if (enterData == true)
{
foreach (char c in Input.inputString)
{
if (c == ’ ')
{
Restart(false);
}
else if ((c == ’
’ || c == ‘\r’) && playerText.Length > 0)
{
Restart(true);
}
else if (c == ‘\b’)
{
if (playerText.Length != 0)
{
playerText = playerText.Substring(0, playerText.Length - 1);
}
}
else if (c == ‘0’ || c == ‘1’ || c == ‘2’ || c == ‘3’ || c == ‘4’ || c == ‘5’ || c == ‘6’ || c == ‘7’ || c == ‘8’ || c == ‘9’)
{
playerText += c;
if (enteredC == false)
{
enteredC = true;
}
}
}
if (enteredC == true)
{
nameText.text = playerText;
}
}
}
}

/*
 * Saved text
 * 
 * 
 * 
 */

I know it’s long. Here’s for my button scripts.

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

public class NewPlayer : MonoBehaviour {

    public GameObject fileManager;

    public void ButtonPress() //I use this for the onClick command
    {
        fileManager.GetComponent<FileManager>().buttonPressed = this.name;
    }
}

/*
 * Saved text
 * 
 * 
 * 
 */

Bottom line for my question, it only compares this new name to the most recent addition to the list. I want it to not have ANY dupe names.

Query: Would moving ‘uniqueName = true;’ above the foreach loop, or changing it in some manner help this? I’ll go test this.

Not sure what the deal is, or why exactly it worked like this, but I made a new list called PlayerNames, filled with strings.

uniqueName = true;
foreach (string s in PlayerNames)
{
    if (s == playerName)
    {
        uniqueName = false;
    }
}
if (uniqueName == true)
{
    nameText.text = "Initiative [0-10] (To Skip, Press Space)";
    enteredC = false;
    player.Name = playerName;
    player.Type = playerType;
    enterData = true;
    naming = false;
    PlayerNames.Add(playerName);
}
if (uniqueName == false)
{
    enteredC = false;
    nameText.text = "Please Choose A Unique Name";
    playerName = "";
}

Now goes in place of what it was before. Note how I add the playerName to the new list and check off the new list rather than my players. It’s open for more bugs and glitches but it fixes my most immediate problem so oh well.