How do I remove the first object from this list?

How do I remove the first object from this list?
I want to always remove 0 if Player is greater than 3 but the problem is I don’t know how to remove the first object in my list using code.

  [SerializeField] List <GameObject> numberOfPlayers;
    [SerializeField] GameObject grave;
    // Use this for initialization
    void Start () {
        playerRigid = GetComponent<Rigidbody2D>();
        box = GetComponent<BoxCollider2D>();
        manageGame = FindObjectOfType<ManageGame>();
        numberOfPlayers.AddRange(GameObject.FindGameObjectsWithTag("Player"));
    }

    // Update is called once per frame
    void Update()
    {

        player = GameObject.FindGameObjectsWithTag("Player").Length;

        if (hasDied == false)
        {
            Move();
        }
         if (player >= 3)
        {
            numberOfPlayers.Remove(gameObject);

Use the RemoveAt method: List<T>.RemoveAt(Int32) Method (System.Collections.Generic) | Microsoft Learn

numberOfPlayers.RemoveAt(0);

Error: Cannot convert from int to unity engine.gameobject

Sounds like you’re trying to use “Remove” instead of “RemoveAt”.

1 Like

Thank you so much

1 Like