Why does IndexOf not return the right index?

for (int i = 0; i < playerList.Count; i++)
{
Debug.Log("For Loop Index: " + i);

        var player = playerList*;*

Debug.Log(“Is this the index:” + playerList.IndexOf(player));
}
Hey! So I ran this loop in a LateUpdate(), because I need a text prefab to be attached to a player GameObject, and when I ask the index of the player which was fetched by the “i = 0” index, he gives me back “0”, but when I ask the index of the player which was fetched by the “i = 1” index, he gives me back “0” again! Does anyone know why and what I can do?

It’s not returning an incorrect index at all. You don’t have any logic to differentiate the player from the values in the array, so you’re actually going to receive log statements in the quantity 2 * playerList.Count ^ playerList.Count. It may not appear that way if you have message collapsing enabled on your console, but it’s there. In other words, it’s simply printing two statements for each player for each player.